M
MarkPowell
Hi,
I am fairly new to VBA and Excel/Word and have been trying to automat
a sheet we have, I have created the Excel Sheet and unfortunately th
Word doc was created sometime ago and cannot be changed.
I have searched this forum and found this code:
Code
-------------------
Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("P:\InstallShield Metrics\GSS_Install_Jan04.Doc") ' open a document
' or
'Set wrdDoc = wrdApp.Documents.Open("P:\InstallShield Metrics\GSS_Install_Jan04.Doc")
' open an existing document
' example word operations
With wrdDoc
For i = 1 To 100
.Content.InsertAfter "Here is a example test line #" & i
.Content.InsertParagraphAfter
Next i
If Dir("P:\InstallShield Metrics\GSS_Install_Jan04.Doc") <> "" Then
Kill "P:\InstallShield Metrics\GSS_Install_Jan04.Doc"
End If
.SaveAs ("P:\InstallShield Metrics\GSS_Install_Jan04.Doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
-------------------
Which does the first part of opening the Word doc I want (trie
recording a macro to do this but that doesn't work)
The next step is to copy certain cell data into columns/rows in Word.
Firstly, can this be done?
Secondly, if so how would I go about getting, data in excel cell J2
to copy to Row 19, Column 2 in Word?
Any help much appreciated.
TIA,
Mark
I am fairly new to VBA and Excel/Word and have been trying to automat
a sheet we have, I have created the Excel Sheet and unfortunately th
Word doc was created sometime ago and cannot be changed.
I have searched this forum and found this code:
Code
-------------------
Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("P:\InstallShield Metrics\GSS_Install_Jan04.Doc") ' open a document
' or
'Set wrdDoc = wrdApp.Documents.Open("P:\InstallShield Metrics\GSS_Install_Jan04.Doc")
' open an existing document
' example word operations
With wrdDoc
For i = 1 To 100
.Content.InsertAfter "Here is a example test line #" & i
.Content.InsertParagraphAfter
Next i
If Dir("P:\InstallShield Metrics\GSS_Install_Jan04.Doc") <> "" Then
Kill "P:\InstallShield Metrics\GSS_Install_Jan04.Doc"
End If
.SaveAs ("P:\InstallShield Metrics\GSS_Install_Jan04.Doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
-------------------
Which does the first part of opening the Word doc I want (trie
recording a macro to do this but that doesn't work)
The next step is to copy certain cell data into columns/rows in Word.
Firstly, can this be done?
Secondly, if so how would I go about getting, data in excel cell J2
to copy to Row 19, Column 2 in Word?
Any help much appreciated.
TIA,
Mark