Word Automation via Visio

J

JWS315

I am trying to use Word via Visio to produce a document. I will not know
what version of Word users will have so I have tried to use the following
code and get an error variable not found on the following lines

docFinal.PageSetup.Orientation = wdOrientPortrait
..ParagraphFormat.Alignment = wdAlignParagraphCenter
wdApp.Selection.EndKey unit:=wdStory

Below is the code I am using - Any Help would be greatly appreciated!

Jerry

Function CreateWordDoc(ByVal strType As Integer)
Dim strFilter As String
Dim fname As String
Dim message As String
Dim Response As String
Dim wdFname As String
Dim docFinal As Object
Dim myRange As Object
Dim runDate As String
Dim docRange As Object
Dim intConnect As Integer
Dim intFromToConnect As Integer
Dim strTitle As String
Dim wdApp As Object

On Error GoTo CreateWordDoc_Error

Const ERR_APP_NOTFOUND As Long = 429
' Attempt to create late-bound instance of Word application to determine if
installed
Set wdApp = CreateObject("Word.Application")
If Err.Number = ERR_APP_NOTFOUND Then
MsgBox "Word is not installed on this computer, No reports can be
generated", vbExclamation, "Word Not Installed"
wdApp.Quit
Exit Function
End If



wdApp.Visible = True
Set docFinal = wdApp.Documents.Add
docFinal.PageSetup.Orientation = wdOrientPortrait
docFinal.PageSetup.DifferentFirstPageHeaderFooter = False
runDate = Format(Date, "mmmm, yyyy")

Select Case strType
Case 1
strTitle = "Process descriptions by Location for"
Case 2
strTitle = "Process descriptions by Role for"
End Select

'Insert a title page
Set myRange = wdApp.Selection.Range
With myRange
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InsertAfter strTitle & vbCrLf & " " & vbCrLf & ""
.InsertAfter strMapName & vbCrLf & " " & vbCrLf & " " & vbCrLf & ""
.InsertAfter " " & vbCrLf & " " & vbCrLf & ""
.Font.Size = "24"
.Italic = True
.Font.Name = "arial"
.Bold = True
End With
wdApp.Selection.EndKey unit:=wdStory
Set myRange = wdApp.Selection.Range
With myRange
.InsertAfter "" & runDate & ""
.InsertAfter " " & vbCrLf & " " & vbCrLf & " " & vbCrLf & " " &
vbCrLf & ""
.Font.Size = "18"
.Font.Name = "arial"
.Bold = False
End With
wdApp.Selection.EndKey unit:=wdStory
 
J

Jean-Guy Marcil

JWS315 was telling us:
JWS315 nous racontait que :
I am trying to use Word via Visio to produce a document. I will not
know what version of Word users will have so I have tried to use the
following code and get an error variable not found on the following
lines

docFinal.PageSetup.Orientation = wdOrientPortrait
.ParagraphFormat.Alignment = wdAlignParagraphCenter
wdApp.Selection.EndKey unit:=wdStory

I believe that in late binding you cannot use the constant names.
Replace the constants with their numerical values

wdOrientPortrait = 0
wdAlignParagraphCenter = 1
wdStory = 6

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

JWS315

Jean-Guy,

Thanks, that seems to fix the issue. Where can I find all the numerical
values for other constants?

Jerry
 
J

Jean-Guy Marcil

JWS315 was telling us:
JWS315 nous racontait que :
Jean-Guy,

Thanks, that seems to fix the issue. Where can I find all the
numerical values for other constants?

Browse the Object model in the Word VBA editor, or create a reference to the
Word object model in Visio. Then select a constant in the list of constants
and note the numerical value in the window footer.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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