I have the following code in a Visual Basic 6 standard exe project. On
my computer, the development computer, it works fine.

Dim ObjH as variant
Set objH = CreateObject ("Shell.Application")

However, when the same line of code is executed on another computer,
it gets a run time error "object variable or with block variable not
set". This line of code is basically instantiating an object variable
to point to an object application in the class named shell. Is there
a Visual Basic reference or dll required to use this line? Does
anyone know why this is occurring and what I can do to fix it. Thanks
in advance.

Why does Createobject work on one computer but not another? by Anuj

Anuj
Tue Jul 29 03:24:58 CDT 2003

You would need to register the DLL contaning the Shell
class on the target machine also. The code work fine on ur
development machine because the dll would be registered
there.

Try registering the dll using regsvr32 "dllname"

Ciao,
~ Anuj

>-----Original Message-----
>I have the following code in a Visual Basic 6 standard
exe project. On
>my computer, the development computer, it works fine.
>
>Dim ObjH as variant
>Set objH = CreateObject ("Shell.Application")
>
>However, when the same line of code is executed on
another computer,
>it gets a run time error "object variable or with block
variable not
>set". This line of code is basically instantiating an
object variable
>to point to an object application in the class named
shell. Is there
>a Visual Basic reference or dll required to use this
line? Does
>anyone know why this is occurring and what I can do to
fix it. Thanks
>in advance.
>.
>

Re: Why does Createobject work on one computer but not another? by mayayana

mayayana
Tue Jul 29 08:42:24 CDT 2003

In Project -> References browse to SHDOC401.DLL.
It will show up as "Microsoft Shell Controls and Automation".
It will show in the Object Browser as "Shell32"
The machine needs to have Active Desktop installed
because SHDOC401.DLL is part of that. In some cases
Win95 and NT4 may not have SHDOC401.DLL, if they never
had IE4 installed on them.

--
--
Gary <garyy@globalipgroup.com> wrote in message
news:87390280.0307282306.1cea7211@posting.google.com...
> I have the following code in a Visual Basic 6 standard exe project. On
> my computer, the development computer, it works fine.
>
> Dim ObjH as variant
> Set objH = CreateObject ("Shell.Application")
>
> However, when the same line of code is executed on another computer,
> it gets a run time error "object variable or with block variable not
> set". This line of code is basically instantiating an object variable
> to point to an object application in the class named shell. Is there
> a Visual Basic reference or dll required to use this line? Does
> anyone know why this is occurring and what I can do to fix it. Thanks
> in advance.



Re: Why does Createobject work on one computer but not another? by Michael

Michael
Tue Jul 29 11:52:08 CDT 2003

Gary wrote:
> I have the following code in a Visual Basic 6 standard exe project. On
> my computer, the development computer, it works fine.
>
> Dim ObjH as variant
> Set objH = CreateObject ("Shell.Application")
>
> However, when the same line of code is executed on another computer,
> it gets a run time error "object variable or with block variable not
> set". This line of code is basically instantiating an object variable
> to point to an object application in the class named shell. Is there
> a Visual Basic reference or dll required to use this line? Does
> anyone know why this is occurring and what I can do to fix it. Thanks
> in advance.


On older OSes (Win95 and NT4) you need to have done an IE4 'Desktop Update'
to have active desktop capabilities (i.e., shell32.dll or later).

It *is* possible to do this after the fact with IE5 or later already
installed.

See these threads:

Google Search: IE4Shell group:microsoft.public.scripting.*
http://groups.google.com/groups?q=IE4Shell%20%20group:microsoft.public.scripting.*&num=100&scoring=d


--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp


Re: Why does Createobject work on one computer but not another? by Michael

Michael
Tue Jul 29 11:53:14 CDT 2003


That should have been...

"...(i.e., shell32.dll 4.71 or later)...."

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp


Re: Why does Createobject work on one computer but not another? Object varaible or with block variable not set by garyy

garyy
Tue Jul 29 15:24:45 CDT 2003

Hello,

Thanks for the help and suggestion. Adding the reference to the
Microsoft Shell Controls and Automation solved the problem (which I am
guessing also registers the library). However, later in my code (3
lines later) I get the same error "object variable or with block
variable not set" on the line of code:

Set oFolderItem = oFolder.ParseName(File1.FileName)

Does anyone know why and how can solve this error? Any help is most
appreciated. As a reminder, this code works okay on my computer.
However, on another computer, it returns an error.

I checked the object browser in Visual Basic to make sure the function
ParseName existed and it returns a FolderItem. The object browser
list:


Function ParseName(bName As String) As FolderItem
Member of Shell32.Folder

What I am doing is retrieving the file properties of a file. (To see
these properies, one would normally right click the file | select
properties | Click the Summary Tab and you will see properties such as
Title, Subject, Category, etc.) The following code works on my
computer, just not on another target computer for some reason.

In the code below, you will also see I use late binding instead of
early binding because early binding did not compile. For example,
"dim oShell as new shell.application"

The complete code block I have is:
?all variables are assumed to be variant
?file1 is a file list box control
Dim oShell
Dim oFolder
Dim oFolderItem
Dim sDir

sDir = File1.Path & "\"

Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(sDir)
If (Not oFolder Is Nothing) Then
Set oFolderItem = oFolder.ParseName(File1.FileName)
If (Not oFolderItem Is Nothing) Then
FileInfo!txtName.Text =
oFolderItem.ExtendedProperty("Title")
'retreive the author
MsgBox "retrieving the author from the file
properties"
FileInfo!txtPublisher.Text =
oFolderItem.ExtendedProperty("Author")
Else
MsgBox "Cannot retrieve file properties"
End If
End If
Set oShell = Nothing
Set oFolder = Nothing
Set oFolderItem = Nothing

?
Thanks so much again.

Re: Why does Createobject work on one computer but not another? Object varaible or with block variable not set by mayayana

mayayana
Tue Jul 29 21:54:58 CDT 2003

> Function ParseName(bName As String) As FolderItem
> Member of Shell32.Folder

The complete code block I have is:
> 'all variables are assumed to be variant
> 'file1 is a file list box control
> Dim oShell
> Dim oFolder
> Dim oFolderItem
> Dim sDir
>
> sDir = File1.Path & "\"
>
> Set oShell = CreateObject("Shell.Application")
> Set oFolder = oShell.NameSpace(sDir)

All variables are assumed to be variant? You can't just
transfer script code; VB uses data types. As it says above,
ParseName returns a FolderItem, not a variant.

Dim oShell as Shell (not certain about that one)
Dim oFolder as Folder
Dim oFolderItem as FolderItem

(If you're also using another folder object, such as FSO
folder, you should declare it as: Dim oFolder as Shell32.Folder)

Set oShell = New Shell
Set oFolder = oShell.NameSpace....etc.

Also, File1 will be an unknown object if your code is in
a module outside of the form.


--
--
Gary <garyy@globalipgroup.com> wrote in message
news:87390280.0307291224.931a737@posting.google.com...
> Hello,
>
> Thanks for the help and suggestion. Adding the reference to the
> Microsoft Shell Controls and Automation solved the problem (which I am
> guessing also registers the library). However, later in my code (3
> lines later) I get the same error "object variable or with block
> variable not set" on the line of code:
>
> Set oFolderItem = oFolder.ParseName(File1.FileName)
>
> Does anyone know why and how can solve this error? Any help is most
> appreciated. As a reminder, this code works okay on my computer.
> However, on another computer, it returns an error.
>
> I checked the object browser in Visual Basic to make sure the function
> ParseName existed and it returns a FolderItem. The object browser
> list:
>
>
> Function ParseName(bName As String) As FolderItem
> Member of Shell32.Folder
>
> What I am doing is retrieving the file properties of a file. (To see
> these properies, one would normally right click the file | select
> properties | Click the Summary Tab and you will see properties such as
> Title, Subject, Category, etc.) The following code works on my
> computer, just not on another target computer for some reason.
>
> In the code below, you will also see I use late binding instead of
> early binding because early binding did not compile. For example,
> "dim oShell as new shell.application"
>
> The complete code block I have is:
> 'all variables are assumed to be variant
> 'file1 is a file list box control
> Dim oShell
> Dim oFolder
> Dim oFolderItem
> Dim sDir
>
> sDir = File1.Path & "\"
>
> Set oShell = CreateObject("Shell.Application")
> Set oFolder = oShell.NameSpace(sDir)
> If (Not oFolder Is Nothing) Then
> Set oFolderItem = oFolder.ParseName(File1.FileName)
> If (Not oFolderItem Is Nothing) Then
> FileInfo!txtName.Text =
> oFolderItem.ExtendedProperty("Title")
> 'retreive the author
> MsgBox "retrieving the author from the file
> properties"
> FileInfo!txtPublisher.Text =
> oFolderItem.ExtendedProperty("Author")
> Else
> MsgBox "Cannot retrieve file properties"
> End If
> End If
> Set oShell = Nothing
> Set oFolder = Nothing
> Set oFolderItem = Nothing
>
> .
> Thanks so much again.