Code Problem

G

GastonFranzini

Hi, I havesome trouble making ths excel macro work.
What I need to do is to open a word document that is uplodaded by it´s
linked data to the excel, then I need to save it and then print it.
The troubles are that it waits the application to finish when it
already finished and then the word asks me save normal.dot.
Thanks in advace for the help.


-----------------------------------------
Sub wordchage()

Dim WordApp As Object

Set WordApp = CreateObject("Word.Application")

fpath = ThisWorkbook.Path

doc = fpath & "\" & ("Base.doc")
Sheets("Incumbent").Select
LetterTemplate = doc
fname = Range("A3")
fnamedoc = fname & ".doc"
With WordApp

..Documents.Open LetterTemplate
..Visible = True

End With

fname = fname & ".pdf"
WordApp.ActiveDocument.PrintOut

WordApp.ActiveDocument.SaveAs Filename:=fpath & "\" & fnamedoc


WordApp.Quit
Set WordApp = Nothing


End Sub
 
J

Jonathan West

Hi Gaston

How to find out whether Word has finished printing
http://www.word.mvps.org/FAQs/MacrosVBA/WaitForPrint.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Hi, I havesome trouble making ths excel macro work.
What I need to do is to open a word document that is uplodaded by it´s
linked data to the excel, then I need to save it and then print it.
The troubles are that it waits the application to finish when it
already finished and then the word asks me save normal.dot.
Thanks in advace for the help.


-----------------------------------------
Sub wordchage()

Dim WordApp As Object

Set WordApp = CreateObject("Word.Application")

fpath = ThisWorkbook.Path

doc = fpath & "\" & ("Base.doc")
Sheets("Incumbent").Select
LetterTemplate = doc
fname = Range("A3")
fnamedoc = fname & ".doc"
With WordApp

..Documents.Open LetterTemplate
..Visible = True

End With

fname = fname & ".pdf"
WordApp.ActiveDocument.PrintOut

WordApp.ActiveDocument.SaveAs Filename:=fpath & "\" & fnamedoc


WordApp.Quit
Set WordApp = Nothing


End Sub
 
G

GastonFranzini

Thanks Jonathan that really helped,
Now I have 2 problems, 1_ when I try to quit the wordapp word prompts
to save Normal.dot. " This file is in use by another application or
user"
2_ When printout PDF prompts for the
filename and the named argument printout filename:= fnamepdf doesn't
work.
Thanks in advance
 
J

Jonathan West

Thanks Jonathan that really helped,
Now I have 2 problems, 1_ when I try to quit the wordapp word prompts
to save Normal.dot. " This file is in use by another application or
user"

Add this line just before you quit Word

Wordapp.NormalTemplate.Saved = True
2_ When printout PDF prompts for the
filename and the named argument printout filename:= fnamepdf doesn't
work.
Thanks in advance

What printer driver are you using? Have you selected the appropriate
printer? Most generation of PDF involves the initial creation of a
Postscript file followed by conversion to PDF using Acrobat Distiller or one
of its free alternatives.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top