Opening a Word doc & Copying files 
Author Message
 Opening a Word doc & Copying files

I'm a relative newbie trying to figure out two things that are probably very
simple.
Some background-- what I'm making is an autorun.exe program to put on a CD.
The program will autostart and present a list of choices.  The object is to
distribute a large collection of family photos and genealogy databases to
other members of my family whose computer experience is limited.  The first
two buttons use the following syntax:
Dim RetVal
RetVal = Shell("f:\programs\imageaxs.exe", 1)
to invoke the installers for two database programs.  I will remove the
absolute paths once all the files are in the same folder on the CD.  This
works OK.
The next button opens a copy of Word 97 and loads my great-grandfather's
autobiography.  This is the code:
Dim RetVal1
RetVal1 = Shell("e:\progra~1\micros~1\office\winword.exe /o
C:\jeff\grandp~1.doc", 1)
This works fine as long as winword.exe is located at the above path, but
what if it is not?  When you double-click on a Word doc in Explorer, Windows
knows it is associated with winword.exe and knows where it is.  How do I get
a VB app to know this also?

The last button (except for the Exit button, which is one of the few things
I do not need help with) Is supposed to copy three database files from the
CD to the hard drive.  I got it mostly working using this:

Private Sub cmdCopy_Click()

Dim SourceFile, DestinationFile
Dim SourceFile2, DestinationFile2
Dim SourceFile3, DestinationFile3

SourceFile = "f:\progra~1\family~1.mdb"
SourceFile2 = "f:\progra~1\family~1.ldb"
SourceFile3 = "f:\progra~1\family~1.iax"

MkDir "c:\family"
DestinationFile = "c:\family\family~1.mdb"
DestinationFile2 = "c:\family\family~1.ldb"
DestinationFile3 = "c:\family\family~1.iax"

FileCopy SourceFile, DestinationFile
FileCopy SourceFile2, DestinationFile2
FileCopy SourceFile3, DestinationFile3

End Sub

This usually works, although if there is already a directory called
c:\family the program crashes.  Also I cannot use the long filenames.  How
do I do that?
I wanted to give the user a choice of the folder the files are copied to, so
I created a new form with a DriveListBox and a DirListBox, which now works
OK.  What I can't figure out is how to tell the app to copy all three files
to whatever folder is selected in the DirListBox.  The original filenames
should remain the same.
I am using VB5 Enterprise.

Thanks,

Jeff



Mon, 16 Jul 2001 03:00:00 GMT  
 Opening a Word doc & Copying files
Hi Jeff,
I'll try to help you with this.

Quote:
>Dim RetVal1
>RetVal1 = Shell("e:\progra~1\micros~1\office\winword.exe /o
>C:\jeff\grandp~1.doc", 1)
>This works fine as long as winword.exe is located at the above path, but
>what if it is not?  When you double-click on a Word doc in Explorer, Windows
>knows it is associated with winword.exe and knows where it is.  How do I get
>a VB app to know this also?

You can't use the built in Shell function for this. Use the API-function
ShellExecute instead. Add the following lines to a bas-module in your program:

Global Const SW_SHOW = 5
Declare Function ShellExecute Lib "shell32.dll" Alias _
 "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
 As String, ByVal lpFile As String, ByVal lpParameters _
 As String, ByVal lpDirectory As String, ByVal nShowCmd _
 As Long) As Long

Then in the buttons Click event type the following:

Dim RetVal1 as Long
RetVall = ShellExecute(0, "open", "C:\jeff\grandp~1.doc", _
 "", "", SW_SHOW)

Quote:
>MkDir "c:\family"
[snip]
>This usually works, although if there is already a directory called
>c:\family the program crashes.  Also I cannot use the long filenames.  How
>do I do that?

Your program doesn't crash do it? Don't you get a run-time error 75 message?
This is not crashing. You get the error because you tried to create a directory
that already exist. You can handle such error messages, actually error handling
is a pretty important thing to do in a program. Try typing "On Error Resume
Next" (without quotes) before the MkDir line and then type "On Error Goto 0"
after the MkDir line. "On Error Resum Next" basically tell VB to ignore any
errors occuring after this line, and "On Error Goto 0" tells VB to not ignore
them anymore. I advise you to learn error handling, it will come handy later on.
As for the prob with long filenames I can't see why this is.

Quote:
>OK.  What I can't figure out is how to tell the app to copy all three files
>to whatever folder is selected in the DirListBox.

DestinationFile = DirListBox.Path & "\family~1.mdb"
DestinationFile2 = DirListBox.Path & "\family~1.ldb"
DestinationFile3 = DirListBox.Path & "\family~1.iax"

Hope this helps!

Sincerely,
Henrik Grotle
N-6800 F?rde, Norway


Software developer VB4, RPG, HTML, Perl

To reply to this posting please remove nospam. from the e-mail adress.



Mon, 16 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Printing multiple Word doc files without opening each in word

2. Opening a Word97 doc as a copy with no doc title

3. How to copy MS Word doc file into RichTextBox

4. Open word 97 doc with doc name as variable

5. BuiltInDocumentProperties from non-Word text files + testing if a DOC file is a Word file

6. Opening a Word Doc from Access with File Name Stored in a Table

7. using word to open an html file and save it as .doc

8. Insert RTF into open Word doc w/o temp files

9. Word doc/rtf files won't open from Explorer shortcuts

10. opening a word (.doc) and Text (.txt) file

11. Get the file name of an already open word doc

12. open doc/excel file in frame with Word/Excel menubar

 

 
Powered by phpBB® Forum Software