Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Simulation in operations research using Excel | Excel Worksheet Functions | |||
Excel Iterations? Conditional Operations? | Excel Discussion (Misc queries) | |||
Excel Iterations? Conditional Operations? | Excel Worksheet Functions | |||
OWC operations in Excel | Excel Discussion (Misc queries) | |||
Operations on .DAT file in Excel... | Excel Programming |