Opening word documents with a macro

rmcbreen

New Member
Joined
Oct 22, 2002
Messages
26
I am tring to link a workbook to a word document. Basically I want to run a Macro that will open the word document and print it. When I try to record the macro, I get an error that says *.doc files are not supported by excel. Any thoughts?

Thanks

Ryan
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You need to first call the Word application because you can't open a Word doc from Excel.

Try this that I stole from somewhere else:

First set a reference to the Word 8.0-object (it's somewhere in tools).
Then use this code:

dim x as new word.application
dim y as new word.document

set y=x.documents.open ("docum.doc")

instead of docum.doc use the name of your word-document including the path.
This way the worddocument is loaded into memory. To make it visisble type:

y.visible=true
 
Upvote 0
Hi

Not quite wat you ask but gives the syntax to create a word session - this code will send data over to work, which might be larger part of whnat you want, also some code in WORD from VBA Excel to give idea of controlling Word from Excel enviroment

Hope this gets you started,

Jack
 
Upvote 0
Ok Oppps forget this bit, kinda important as well

Sub Excel_to_Word_JackintheUK()

Range("A1:A20").Select
Selection.Copy

Set Word6 = CreateObject("Word.Basic")
With Word6
If UCase(Left(Application.OperatingSystem, 3)) <> "MAC" Then
.AppRestore
.AppMaximize 1
Else
AppActivate "Microsoft Word"
End If
.FileNewDefault
'.InsertPara
.Insert "Jack - Test from Excel"
.startofline 15
' .Bold
' .CenterPara
'.startofline 15
Selection.PasteSpecial Paste:=xlValues, operation:=xlNone, _
skipblanks:=False, Transpose:=False
Application.CutCopyMode = False

End With



End Sub
 
Upvote 0
Elaborating a bit on Dreamboat's guidance, you include your Word object library from your VB Editor page, Tools/References.

The only pitfall could be if you give the code to others to use, and their references aren't properly set up. In that event, you'll get to learn about AddFromFile and AddFromGuid nethods so that your code automatically adds the needed references.
Tom

_________________
This message was edited by Tom Morales on 2002-10-26 11:01
 
Upvote 0
Thanks for all of the help, I just got a chance to look at your advice, and am going to try to get everything to work out before I leave work.

Thanks again.

Ryan
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top