Hi! I am trying to output from Excel to Word using the following code. The data needs to retain the font.color, .bold, .italic,.underline and .strikethrough properties of the ActiveCell.Value.
Tried 3 different ways:
1. Open "c:\TESTFILE.doc" For Output As #1
Range("A1").Select
ActiveCell.Offset(somenum, 0).Select
Print #1, ActiveCell.Value;
Close #1
This wrote the data to the file but would not format as required.
2. Dim channelNumber As String 'Application Handle
Dim FullPath As String
FullPath = "C:\MyTestFile.Doc"
channelNumber = Application.DDEInitiate( _
app:="WinWord", topic:=FullPath)
Range("A1").Select
ActiveCell.Offset(somenum, 0).Select
ActiveCell.Copy
SendKeys "^v", True
Application.DDETerminate channelNumber
It opens the file but nothing gets written to it. Also, not sure if this will retain the formatting/styles/font in Word.
3. Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open _
(Filename:="C:\myTestFile.doc")
Range("A1").Select
ActiveCell.Offset(somenum, 0).Select
ActiveCell.Copy
SendKeys "^v", True
wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
Again nothing happens.
In all 3 cases, I'm not getting any errors.
Can anybody help?! Thanks in advance!
Tried 3 different ways:
1. Open "c:\TESTFILE.doc" For Output As #1
Range("A1").Select
ActiveCell.Offset(somenum, 0).Select
Print #1, ActiveCell.Value;
Close #1
This wrote the data to the file but would not format as required.
2. Dim channelNumber As String 'Application Handle
Dim FullPath As String
FullPath = "C:\MyTestFile.Doc"
channelNumber = Application.DDEInitiate( _
app:="WinWord", topic:=FullPath)
Range("A1").Select
ActiveCell.Offset(somenum, 0).Select
ActiveCell.Copy
SendKeys "^v", True
Application.DDETerminate channelNumber
It opens the file but nothing gets written to it. Also, not sure if this will retain the formatting/styles/font in Word.
3. Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open _
(Filename:="C:\myTestFile.doc")
Range("A1").Select
ActiveCell.Offset(somenum, 0).Select
ActiveCell.Copy
SendKeys "^v", True
wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
Again nothing happens.
In all 3 cases, I'm not getting any errors.
Can anybody help?! Thanks in advance!