By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,221 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,221 IT Pros & Developers. It's quick & easy.

How to change orientation in ms word with vba

P: n/a
Hello all,
I am trying to programmatically change the orientation of a MS Word Document
to landscape. I must be doing something wrong cause it does not work ... can
anybody help me with this?
Code is below ....
Much obliged ...
Ronny Sigo

Dim appWD As Object
Dim myDoc As Object
Dim sSavestring As String
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
With appWD
Set myDoc = .Documents.Add
.Documents(1).Activate
With .ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
.WindowState = wdWindowStateMaximize
With .Selection
cm = 1
.PageSetup.LeftMargin = CentimetersNaarPunten(cm)
.PageSetup.RightMargin = CentimetersNaarPunten(cm)
.PageSetup.TopMargin = CentimetersNaarPunten(cm)
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.LineSpacing = 13
.Font.Name = "Arial"
.Font.Color = vbRed
.Font.Italic = True
.InlineShapes.AddPicture FileName:= _
"\\MyPath\Myfile.bmp", LinkToFile:=False, _
SaveWithDocument:=True
.insertafter Text:=" Lijst alle contacten de4000 "
.Font.Size = 24
.Font.Bold = True
.Collapse Direction:=wdCollapseEnd
.insertafter Text:=vbCrLf
.insertafter Text:=vbTab & vbTab & vbTab
.insertafter Text:="Bestand aangemaakt op: "
.Font.Size = 12
.Font.Bold = False
.insertafter Text:=Date & vbCr & vbCr & vbCr
.Collapse Direction:=wdCollapseEnd
End With
sSavestring = "\\MyPath\MyFile" & Year(Date) & "-" & Month(Date)
& "-" & _
Day(Date)
myDoc.SaveAs FileName:=sSavestring
End With
'appWD.Quit
Set appWD = Nothing
If theError = 429 Then appWD.Quit
Set appWD = Nothing
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Ronny Sigo" <roon ad skynet.be> wrote in message news:<41***********************@news.skynet.be>...
Hello all,
I am trying to programmatically change the orientation of a MS Word Document
to landscape. I must be doing something wrong cause it does not work ... can
anybody help me with this?
Code is below ....
Much obliged ...
Ronny Sigo

Dim appWD As Object
Dim myDoc As Object
Dim sSavestring As String
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
With appWD
Set myDoc = .Documents.Add
.Documents(1).Activate
With .ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
.WindowState = wdWindowStateMaximize
With .Selection
cm = 1
.PageSetup.LeftMargin = CentimetersNaarPunten(cm)
.PageSetup.RightMargin = CentimetersNaarPunten(cm)
.PageSetup.TopMargin = CentimetersNaarPunten(cm)
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.LineSpacing = 13
.Font.Name = "Arial"
.Font.Color = vbRed
.Font.Italic = True
.InlineShapes.AddPicture FileName:= _
"\\MyPath\Myfile.bmp", LinkToFile:=False, _
SaveWithDocument:=True
.insertafter Text:=" Lijst alle contacten de4000 "
.Font.Size = 24
.Font.Bold = True
.Collapse Direction:=wdCollapseEnd
.insertafter Text:=vbCrLf
.insertafter Text:=vbTab & vbTab & vbTab
.insertafter Text:="Bestand aangemaakt op: "
.Font.Size = 12
.Font.Bold = False
.insertafter Text:=Date & vbCr & vbCr & vbCr
.Collapse Direction:=wdCollapseEnd
End With
sSavestring = "\\MyPath\MyFile" & Year(Date) & "-" & Month(Date)
& "-" & _
Day(Date)
myDoc.SaveAs FileName:=sSavestring
End With
'appWD.Quit
Set appWD = Nothing
If theError = 429 Then appWD.Quit
Set appWD = Nothing


When I record a macro to change the orientation, Word changes several
PageSetup parameters instead of just .Orientation. Perhaps you could
try including all of these and then try eliminating them one by one
until you have the smallest set necessary.

James A. Fortune
Nov 13 '05 #2

P: n/a
"Ronny Sigo" <roon ad skynet.be> wrote in message news:<41***********************@news.skynet.be>...
Hello all,
I am trying to programmatically change the orientation of a MS Word Document
to landscape. I must be doing something wrong cause it does not work ... can
anybody help me with this?
Code is below ....
Much obliged ...
Ronny Sigo

Dim appWD As Object
Dim myDoc As Object
Dim sSavestring As String
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
With appWD
Set myDoc = .Documents.Add
.Documents(1).Activate
With .ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
.WindowState = wdWindowStateMaximize
With .Selection
cm = 1
.PageSetup.LeftMargin = CentimetersNaarPunten(cm)
.PageSetup.RightMargin = CentimetersNaarPunten(cm)
.PageSetup.TopMargin = CentimetersNaarPunten(cm)
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.LineSpacing = 13
.Font.Name = "Arial"
.Font.Color = vbRed
.Font.Italic = True
.InlineShapes.AddPicture FileName:= _
"\\MyPath\Myfile.bmp", LinkToFile:=False, _
SaveWithDocument:=True
.insertafter Text:=" Lijst alle contacten de4000 "
.Font.Size = 24
.Font.Bold = True
.Collapse Direction:=wdCollapseEnd
.insertafter Text:=vbCrLf
.insertafter Text:=vbTab & vbTab & vbTab
.insertafter Text:="Bestand aangemaakt op: "
.Font.Size = 12
.Font.Bold = False
.insertafter Text:=Date & vbCr & vbCr & vbCr
.Collapse Direction:=wdCollapseEnd
End With
sSavestring = "\\MyPath\MyFile" & Year(Date) & "-" & Month(Date)
& "-" & _
Day(Date)
myDoc.SaveAs FileName:=sSavestring
End With
'appWD.Quit
Set appWD = Nothing
If theError = 429 Then appWD.Quit
Set appWD = Nothing


When I record a macro to change the orientation, Word changes several
PageSetup parameters instead of just .Orientation. Perhaps you could
try including all of these and then try eliminating them one by one
until you have the smallest set necessary.

James A. Fortune
Nov 13 '05 #3

P: n/a
Unless you are programming the change of orientation within Word, other
programme won't know what wdOrientLandscape means.

Replace it with 1 and you should be fine.

Herbert

"Ronny Sigo" <roon ad skynet.be> 在郵件
news:41***********************@news.skynet.be 中撰寫...
Hello all,
I am trying to programmatically change the orientation of a MS Word Document to landscape. I must be doing something wrong cause it does not work ... can anybody help me with this?
Code is below ....
Much obliged ...
Ronny Sigo

Dim appWD As Object
Dim myDoc As Object
Dim sSavestring As String
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
With appWD
Set myDoc = .Documents.Add
.Documents(1).Activate
With .ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
.WindowState = wdWindowStateMaximize
With .Selection
cm = 1
.PageSetup.LeftMargin = CentimetersNaarPunten(cm)
.PageSetup.RightMargin = CentimetersNaarPunten(cm)
.PageSetup.TopMargin = CentimetersNaarPunten(cm)
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.LineSpacing = 13
.Font.Name = "Arial"
.Font.Color = vbRed
.Font.Italic = True
.InlineShapes.AddPicture FileName:= _
"\\MyPath\Myfile.bmp", LinkToFile:=False, _
SaveWithDocument:=True
.insertafter Text:=" Lijst alle contacten de4000 "
.Font.Size = 24
.Font.Bold = True
.Collapse Direction:=wdCollapseEnd
.insertafter Text:=vbCrLf
.insertafter Text:=vbTab & vbTab & vbTab
.insertafter Text:="Bestand aangemaakt op: "
.Font.Size = 12
.Font.Bold = False
.insertafter Text:=Date & vbCr & vbCr & vbCr
.Collapse Direction:=wdCollapseEnd
End With
sSavestring = "\\MyPath\MyFile" & Year(Date) & "-" & Month(Date) & "-" & _
Day(Date)
myDoc.SaveAs FileName:=sSavestring
End With
'appWD.Quit
Set appWD = Nothing
If theError = 429 Then appWD.Quit
Set appWD = Nothing

Nov 13 '05 #4

P: n/a
This works great:)
Thank you Herbert

"Herbert Chan" <he*****@chan.com> schreef in bericht
news:2o************@uni-berlin.de...
Unless you are programming the change of orientation within Word, other
programme won't know what wdOrientLandscape means.

Replace it with 1 and you should be fine.

Herbert

"Ronny Sigo" <roon ad skynet.be> 在郵件
news:41***********************@news.skynet.be 中撰寫...
Hello all,
I am trying to programmatically change the orientation of a MS Word

Document
to landscape. I must be doing something wrong cause it does not work ...

can
anybody help me with this?
Code is below ....
Much obliged ...
Ronny Sigo

Dim appWD As Object
Dim myDoc As Object
Dim sSavestring As String
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
With appWD
Set myDoc = .Documents.Add
.Documents(1).Activate
With .ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
.WindowState = wdWindowStateMaximize
With .Selection
cm = 1
.PageSetup.LeftMargin = CentimetersNaarPunten(cm)
.PageSetup.RightMargin = CentimetersNaarPunten(cm)
.PageSetup.TopMargin = CentimetersNaarPunten(cm)
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.LineSpacing = 13
.Font.Name = "Arial"
.Font.Color = vbRed
.Font.Italic = True
.InlineShapes.AddPicture FileName:= _
"\\MyPath\Myfile.bmp", LinkToFile:=False, _
SaveWithDocument:=True
.insertafter Text:=" Lijst alle contacten de4000 "
.Font.Size = 24
.Font.Bold = True
.Collapse Direction:=wdCollapseEnd
.insertafter Text:=vbCrLf
.insertafter Text:=vbTab & vbTab & vbTab
.insertafter Text:="Bestand aangemaakt op: "
.Font.Size = 12
.Font.Bold = False
.insertafter Text:=Date & vbCr & vbCr & vbCr
.Collapse Direction:=wdCollapseEnd
End With
sSavestring = "\\MyPath\MyFile" & Year(Date) & "-" &

Month(Date)
& "-" & _
Day(Date)
myDoc.SaveAs FileName:=sSavestring
End With
'appWD.Quit
Set appWD = Nothing
If theError = 429 Then appWD.Quit
Set appWD = Nothing


Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.