LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Performing ms word operations from ms Excel.

Most/All my MSWord coding comes from MSWord's macro recorder.

I record what I need to do in MSWord, then try to modify it to work via excel.

For instance, this prints a .doc file:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\document1.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)
WDDoc.PrintOut '.printPreview while testing???
WDDoc.Close savechanges:=False

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

There are a couple of things that can make your coding easier.

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object

Set a reference within the VBE (tools|references) to "microsoft word xx.0 Object
library".

Then you'll get the intellisense and autocomplete for those nicely declared
objects.

After you've tested it, remove that reference and use the generic "as object".
And if you used any of the Word constants, change them to their value.

If you record your macro in word and have trouble incorporating it in excel,
post back with your efforts. Maybe someone will be able to help.

andy wrote:

Hi,

I would like to code a macro in a Excel document that would perform a file
conversion of a word doc to html format. I'm able to activate the word
document using Application.ActivateMicrosoftApp xlMicrosoftWord.

But how to I access to the word macro objects to perform the necessary
automation within word?


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulation in operations research using Excel denise1082 via OfficeKB.com Excel Worksheet Functions 3 July 31st 06 10:46 AM
Excel Iterations? Conditional Operations? [email protected] Excel Discussion (Misc queries) 3 May 30th 06 08:41 AM
Excel Iterations? Conditional Operations? [email protected] Excel Worksheet Functions 4 May 30th 06 08:41 AM
OWC operations in Excel mondayisgreat Excel Discussion (Misc queries) 0 March 3rd 06 03:07 PM
Operations on .DAT file in Excel... steveB Excel Programming 0 May 26th 04 12:00 AM


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"