Connecting Tech Pros Worldwide Forums | Help | Site Map

basic CreateObject syntax question

deko
Guest
 
Posts: n/a
#1: Nov 12 '05
Okay, so I got the common dialog working.

but how to create object to copy selected files?

Dim d As Object
Dim fDialog As Office.FileDialog

Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

If fDialog.Show = True Then
For Each varFile In fDialog.SelectedItems
Set d = CreateObject("FileSystemObject") '<<<=== ???
d.CopyFile varFile, strOrgDir
d.Close
Next
End If





Danny J. Lesandrini
Guest
 
Posts: n/a
#2: Nov 12 '05

re: basic CreateObject syntax question


Try this ...

Dim objScript
Set objScript= CreateObject("Scripting.FileSystemObject")
objScript.CopyFile strSource, strTarget

--

Danny J. Lesandrini
dlesandrini@hotmail.com
http://amazecreations.com


"deko" <dje422@hotmail.com> wrote in message
news:uZ%zb.65970$205.40187@newssvr25.news.prodigy. com...[color=blue]
> Okay, so I got the common dialog working.
>
> but how to create object to copy selected files?
>
> Dim d As Object
> Dim fDialog As Office.FileDialog
>
> Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
>
> If fDialog.Show = True Then
> For Each varFile In fDialog.SelectedItems
> Set d = CreateObject("FileSystemObject") '<<<=== ???
> d.CopyFile varFile, strOrgDir
> d.Close
> Next
> End If
>
>[/color]


MGFoster
Guest
 
Posts: n/a
#3: Nov 12 '05

re: basic CreateObject syntax question


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why not do this:

If fDialog.Show = True Then
For Each varFile In fDialog.SelectedItems
FileCopy varFile, strOrgDir & "\" & varFile
Next
End If

FileCopy is a built-in Access function.

- --
MGFoster:::mgf
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP9DnsIechKqOuFEgEQJd/gCdGtee4Dx7WmMbJVpvFOA+GdEW9SsAoK0C
CtpUqkTIu1p3T9XI4MIXA49e
=nnj3
-----END PGP SIGNATURE-----

deko wrote:
[color=blue]
> Okay, so I got the common dialog working.
>
> but how to create object to copy selected files?
>
> Dim d As Object
> Dim fDialog As Office.FileDialog
>
> Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
>
> If fDialog.Show = True Then
> For Each varFile In fDialog.SelectedItems
> Set d = CreateObject("FileSystemObject") '<<<=== ???
> d.CopyFile varFile, strOrgDir
> d.Close
> Next
> End If
>
>[/color]


Danny J. Lesandrini
Guest
 
Posts: n/a
#4: Nov 12 '05

re: basic CreateObject syntax question


Ooops! You're right. How simple and clean!

Reminds me of something a doctor once said. When presented
with symptoms of an illness, always think simple, basic, instead
of strange and exotic.

"When you hear hoof-beats, think horses, not zebras."
--

Danny J. Lesandrini
dlesandrini@hotmail.com
http://amazecreations.com


"MGFoster" <me@privacy.com> wrote in message
news:HI5Ab.447$rP6.258@newsread2.news.pas.earthlin k.net...[color=blue]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Why not do this:
>
> If fDialog.Show = True Then
> For Each varFile In fDialog.SelectedItems
> FileCopy varFile, strOrgDir & "\" & varFile
> Next
> End If
>
> FileCopy is a built-in Access function.
>
> - --
> MGFoster:::mgf
> Oakland, CA (USA)
> -----BEGIN PGP SIGNATURE-----
> Version: PGP for Personal Privacy 5.0
> Charset: noconv
>
> iQA/AwUBP9DnsIechKqOuFEgEQJd/gCdGtee4Dx7WmMbJVpvFOA+GdEW9SsAoK0C
> CtpUqkTIu1p3T9XI4MIXA49e
> =nnj3
> -----END PGP SIGNATURE-----
>
> deko wrote:
>[color=green]
> > Okay, so I got the common dialog working.
> >
> > but how to create object to copy selected files?
> >
> > Dim d As Object
> > Dim fDialog As Office.FileDialog
> >
> > Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
> >
> > If fDialog.Show = True Then
> > For Each varFile In fDialog.SelectedItems
> > Set d = CreateObject("FileSystemObject") '<<<=== ???
> > d.CopyFile varFile, strOrgDir
> > d.Close
> > Next
> > End If
> >
> >[/color]
>
>[/color]


deko
Guest
 
Posts: n/a
#5: Nov 12 '05

re: basic CreateObject syntax question


Hi and thanks for the reply.

I tried this:

Dim objFile as Object
Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.MoveFile strSource, strDestination
objFile.Close

and got:

Error Number 438: Object doesn't support this property or method

I also tried:

Dim objFile as Object
Set objFile = CreateObject("varFile.FileSystemObject")
objFile.MoveFile strSource, strDestination
objFile.Close

and that didn't work either...

Yes, I am trying to MoveFile now, rather than CopyFile, but the results are
the same either way.


"Danny J. Lesandrini" <dlesandrini@hotmail.com> wrote in message
news:bqqnn0$24vh4v$1@ID-82595.news.uni-berlin.de...[color=blue]
> Try this ...
>
> Dim objScript
> Set objScript= CreateObject("Scripting.FileSystemObject")
> objScript.CopyFile strSource, strTarget
>
> --
>
> Danny J. Lesandrini
> dlesandrini@hotmail.com
> http://amazecreations.com
>
>
> "deko" <dje422@hotmail.com> wrote in message
> news:uZ%zb.65970$205.40187@newssvr25.news.prodigy. com...[color=green]
> > Okay, so I got the common dialog working.
> >
> > but how to create object to copy selected files?
> >
> > Dim d As Object
> > Dim fDialog As Office.FileDialog
> >
> > Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
> >
> > If fDialog.Show = True Then
> > For Each varFile In fDialog.SelectedItems
> > Set d = CreateObject("FileSystemObject") '<<<=== ???
> > d.CopyFile varFile, strOrgDir
> > d.Close
> > Next
> > End If
> >
> >[/color]
>
>[/color]


deko
Guest
 
Posts: n/a
#6: Nov 12 '05

re: basic CreateObject syntax question


Yes, that works great - thanks! But, I also need to MoveFiles... Is there
an equivalent MoveFile? I did not find one in VB Help....

I tried this:

Dim objFile as Object
Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.MoveFile strSource, strDestination
objFile.Close

and got:

Error Number 438: Object doesn't support this property or method

I also tried:

Dim objFile as Object
Set objFile = CreateObject("varFile.FileSystemObject")
objFile.MoveFile strSource, strDestination
objFile.Close

and that didn't work either...

"MGFoster" <me@privacy.com> wrote in message
news:HI5Ab.447$rP6.258@newsread2.news.pas.earthlin k.net...[color=blue]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Why not do this:
>
> If fDialog.Show = True Then
> For Each varFile In fDialog.SelectedItems
> FileCopy varFile, strOrgDir & "\" & varFile
> Next
> End If
>
> FileCopy is a built-in Access function.
>
> - --
> MGFoster:::mgf
> Oakland, CA (USA)
> -----BEGIN PGP SIGNATURE-----
> Version: PGP for Personal Privacy 5.0
> Charset: noconv
>
> iQA/AwUBP9DnsIechKqOuFEgEQJd/gCdGtee4Dx7WmMbJVpvFOA+GdEW9SsAoK0C
> CtpUqkTIu1p3T9XI4MIXA49e
> =nnj3
> -----END PGP SIGNATURE-----
>
> deko wrote:
>[color=green]
> > Okay, so I got the common dialog working.
> >
> > but how to create object to copy selected files?
> >
> > Dim d As Object
> > Dim fDialog As Office.FileDialog
> >
> > Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
> >
> > If fDialog.Show = True Then
> > For Each varFile In fDialog.SelectedItems
> > Set d = CreateObject("FileSystemObject") '<<<=== ???
> > d.CopyFile varFile, strOrgDir
> > d.Close
> > Next
> > End If
> >
> >[/color]
>
>[/color]


deko
Guest
 
Posts: n/a
#7: Nov 12 '05

re: basic CreateObject syntax question


Ah ha...

It's working like a champ now...

The problem was objFile.Close - apparently I don't need to Close this?


"deko" <dje422@hotmail.com> wrote in message
news:Ed7Ab.66132$C97.39248@newssvr25.news.prodigy. com...[color=blue]
> Hi and thanks for the reply.
>
> I tried this:
>
> Dim objFile as Object
> Set objFile = CreateObject("Scripting.FileSystemObject")
> objFile.MoveFile strSource, strDestination
> objFile.Close
>
> and got:
>
> Error Number 438: Object doesn't support this property or method
>
> I also tried:
>
> Dim objFile as Object
> Set objFile = CreateObject("varFile.FileSystemObject")
> objFile.MoveFile strSource, strDestination
> objFile.Close
>
> and that didn't work either...
>
> Yes, I am trying to MoveFile now, rather than CopyFile, but the results[/color]
are[color=blue]
> the same either way.
>
>
> "Danny J. Lesandrini" <dlesandrini@hotmail.com> wrote in message
> news:bqqnn0$24vh4v$1@ID-82595.news.uni-berlin.de...[color=green]
> > Try this ...
> >
> > Dim objScript
> > Set objScript= CreateObject("Scripting.FileSystemObject")
> > objScript.CopyFile strSource, strTarget
> >
> > --
> >
> > Danny J. Lesandrini
> > dlesandrini@hotmail.com
> > http://amazecreations.com
> >
> >
> > "deko" <dje422@hotmail.com> wrote in message
> > news:uZ%zb.65970$205.40187@newssvr25.news.prodigy. com...[color=darkred]
> > > Okay, so I got the common dialog working.
> > >
> > > but how to create object to copy selected files?
> > >
> > > Dim d As Object
> > > Dim fDialog As Office.FileDialog
> > >
> > > Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
> > >
> > > If fDialog.Show = True Then
> > > For Each varFile In fDialog.SelectedItems
> > > Set d = CreateObject("FileSystemObject") '<<<=== ???
> > > d.CopyFile varFile, strOrgDir
> > > d.Close
> > > Next
> > > End If
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


deko
Guest
 
Posts: n/a
#8: Nov 12 '05

re: basic CreateObject syntax question


objFile.Close was the culprit...

I figured this out after discovering the F8 key....

as an aside, it seems I need to put in a breakpoint, then click the sub's
command button on the form in order to step through the sub with F8 - is
there a way step through the sub from within the IDE? When I go to Debug >>
Step Into (or just hit F8 withing the IDE)... nothing happens.

(I get some kind of macro window when trying Run >> Run Sub/User Form)

"deko" <dje422@hotmail.com> wrote in message
news:sh7Ab.66133$2g7.12187@newssvr25.news.prodigy. com...[color=blue]
> Yes, that works great - thanks! But, I also need to MoveFiles... Is there
> an equivalent MoveFile? I did not find one in VB Help....
>
> I tried this:
>
> Dim objFile as Object
> Set objFile = CreateObject("Scripting.FileSystemObject")
> objFile.MoveFile strSource, strDestination
> objFile.Close
>
> and got:
>
> Error Number 438: Object doesn't support this property or method
>
> I also tried:
>
> Dim objFile as Object
> Set objFile = CreateObject("varFile.FileSystemObject")
> objFile.MoveFile strSource, strDestination
> objFile.Close
>
> and that didn't work either...
>
> "MGFoster" <me@privacy.com> wrote in message
> news:HI5Ab.447$rP6.258@newsread2.news.pas.earthlin k.net...[color=green]
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Why not do this:
> >
> > If fDialog.Show = True Then
> > For Each varFile In fDialog.SelectedItems
> > FileCopy varFile, strOrgDir & "\" & varFile
> > Next
> > End If
> >
> > FileCopy is a built-in Access function.
> >
> > - --
> > MGFoster:::mgf
> > Oakland, CA (USA)
> > -----BEGIN PGP SIGNATURE-----
> > Version: PGP for Personal Privacy 5.0
> > Charset: noconv
> >
> > iQA/AwUBP9DnsIechKqOuFEgEQJd/gCdGtee4Dx7WmMbJVpvFOA+GdEW9SsAoK0C
> > CtpUqkTIu1p3T9XI4MIXA49e
> > =nnj3
> > -----END PGP SIGNATURE-----
> >
> > deko wrote:
> >[color=darkred]
> > > Okay, so I got the common dialog working.
> > >
> > > but how to create object to copy selected files?
> > >
> > > Dim d As Object
> > > Dim fDialog As Office.FileDialog
> > >
> > > Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
> > >
> > > If fDialog.Show = True Then
> > > For Each varFile In fDialog.SelectedItems
> > > Set d = CreateObject("FileSystemObject") '<<<=== ???
> > > d.CopyFile varFile, strOrgDir
> > > d.Close
> > > Next
> > > End If
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread