Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word document not accepting margins 1

Status
Not open for further replies.

JTBorton

Technical User
Joined
Jun 9, 2008
Messages
345
Location
DE
I am trying to set the margins on a word document where I have pasted a table from excel. However, after the macro runs and I open the document to inspect it, the margins are all at 0" instead of what I specified. This puts the table out of the print area. I want all of the margins and the gutter to be 0.25". The gutter position and orientation are working just fine.

Dim oWd As Word.Application, oWdoc As Word.Document, oRng As Word.Range
.
. (Determining the size of and copying the excel Table)
.

Set oWd = CreateObject("Word.Application")
Set oWdoc = oWd.Documents.Add
Set oRng = oWdoc.Range

'Copy and paste the spreadsheet onto the document
oWdoc.Sections(1).Range.Paste
With oWdoc.Application.Selection.Tables(1).Rows
.LeftIndent = 0
.Alignment = wdAlignRowCenter
End With

'Document Page Setup
With oWdoc.PageSetup
.Gutter = 0.25
.GutterPos = wdGutterPosTop
.Orientation = wdOrientLandscape
.BottomMargin = 0.25
.TopMargin = 0.25
.LeftMargin = 0.25
.RightMargin = 0.25
.VerticalAlignment = wdAlignVerticalTop
End With


'Close out the document
oWdoc.SaveAs ("e:/WordTrial1.doc")
oWdoc.Close
oWd.Quit
Set oWdoc = Nothing
Set oWd = Nothing
 
A starting point:
.LeftMargin = InchesToPoints(0.25)


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
VBA is so picky. Thats got it, Thanks
 
Hi JTBorton,
VBA is so picky
No, it just needs you to tell it what you mean, in this case, 0.25 of 'what' - points, cm, inches, other.

Cheers


[MS MVP - Word]
 
Personally, I think the pickier a coding language is, the better. Fuzziness can cause...fuzziness. Clear and explicit terms, generally, cause clear and explicit results.

.LeftMargin = 0.25

As macropod points out, 0.25 inches? 0.25 centimetres?

I freely admit there aspects of VBA that are, indeed, ridiculously obtuse, and object concepts and structures that are not - shall we say - consistent.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top