Connecting Tech Pros Worldwide Help | Site Map

basic CreateObject syntax question

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 04:23 PM
deko
Guest
 
Posts: n/a
Default basic CreateObject syntax question

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



  #2  
Old November 12th, 2005, 04:24 PM
Danny J. Lesandrini
Guest
 
Posts: n/a
Default 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]


  #3  
Old November 12th, 2005, 04:25 PM
MGFoster
Guest
 
Posts: n/a
Default 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]


  #4  
Old November 12th, 2005, 04:25 PM
Danny J. Lesandrini
Guest
 
Posts: n/a
Default 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]


  #5  
Old November 12th, 2005, 04:25 PM
deko
Guest
 
Posts: n/a
Default 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]


  #6  
Old November 12th, 2005, 04:25 PM
deko
Guest
 
Posts: n/a
Default 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]


  #7  
Old November 12th, 2005, 04:25 PM
deko
Guest
 
Posts: n/a
Default 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]


  #8  
Old November 12th, 2005, 04:25 PM
deko
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.