Click to See Complete Forum and Search --> : VB Newbie needs help.


Mr. Bean
December 6th, 1999, 05:43 PM
Hello,
I am a Java programmer and do not know much about VB. I am writing a Word Macro and it needs to do the following:
Open up a file ("file.doc");
Read the first line from ("file.doc");
Close ("file.doc") and open up another file with the first line read
Thanks ahead of time. All help greatly appreciated. Mr. Bean

December 6th, 1999, 08:37 PM
'This will load file.txt copy the first line and put it in the second file
Dim LINEIN as string
LINEIN = ""

Open "C:\file.txt" for input as #1
Open "C:\otherfile.txt" for Output as #2

Line input #1, LINEIN
print #2, LINEIN

Close #1, #2

December 6th, 1999, 08:58 PM
In Word click Tools, Macro, Record New Macro and then do everything you wanted the macro to do. When finish stop recording, go Tools, Macro, Macros, select Macro you just created. Click on Edit and you'll see the code (VBA) that performs all things you wanted. You can copy it and paste in VB project. After a small editing you can run it from VB. Don't forget to make reference to Word Object Library (Project, References in VB) and create Word object, something like:

Dim objWord as Word.Application
set objWord = new Word.Application
With objWord
.Visible =true
'your code from word comes here
'............
end with



Vlad