PDA

View Full Version : Word 2010 Printer Settings



NicoleJones
12-07-2011, 06:14 PM
Hi

Is it possible to retrieve the Papersize in the Printer Settings using VBAin Word 2010? I have previously used


APPLICATION.Printer.PaperSize



in Access however it is not working in Word.

Thank you for your help

NJ

Paul_Hossler
12-10-2011, 05:23 PM
.PaperSize is a property of the .PageSetup object




PageSetup.PaperSize PropertyReturns or sets the paper size. Read/write WdPaperSize.
Syntax

expression.PaperSize

expression Required. A variable that represents a PageSetup (http://www.vbaexpress.com/forum/ms-help://MS.WINWORD.DEV.14.1033/WINWORD.DEV/content/HV10329514.htm) object.


Remarks
Setting the PageHeight or PageWidth property changes the PaperSize property to wdPaperCustom.

Example

This example sets the paper size to legal for the first document.
Documents(1).PageSetup.PaperSize = wdPaperLegal

Paul

NicoleJones
12-11-2011, 01:43 PM
Hi Paul

Thank you for your help, what I am after is the printer settings, I work for an internation company that has very strict branding and styles which have been set up in the Normal.dotm.

I used to have a CompanyNormal.dotm setup in the start up file (this used to look at the Normal.dotm settings, however since I am taking that file over this is not an aption) except Word 2010 is looking at the start up file differently and I am wanting to role out the Normal.dotm to the rest of the countries.

So that I dont have to create a Normal.dotm for each location ensuring that the language and papersizing are correct I want some code inserted on load to look at the printer settings and change the page setup accordingly.

I hope this clarifies it a bit better, if I am unable to get it out of the printer settings do you know of any other way that I can pull the information?

Thank you again for your assistance

NJ

Paul_Hossler
12-11-2011, 03:42 PM
I might be misunderstanding. Do you want to get the printer HW properties, or just configure the document to print IAW your branding requirements?

If it's the latter, .PageSetup will allow you to configure the document's sage size and page layout. If it's the former, you might have to use windows API



Sub test()

With ActiveDocument.PageSetup
MsgBox "Paper size is " & .PageHeight & " (H) by " & .PageWidth & " (W) in points"
MsgBox "Paper size is " & PointsToInches(.PageHeight) & " (H) by " & PointsToInches(.PageWidth) & " (W) in inches"


.PaperSize = wdPaperA4

MsgBox "Paper size is " & .PageHeight & " (H) by " & .PageWidth & " (W) in points"
MsgBox "Paper size is " & PointsToInches(.PageHeight) & " (H) by " & PointsToInches(.PageWidth) & " (W) in inches"




.PageHeight = InchesToPoints(6.25)
.PageWidth = InchesToPoints(4)


MsgBox "Paper size is " & .PageHeight & " (H) by " & .PageWidth & " (W) in points"
MsgBox "Paper size is " & PointsToInches(.PageHeight) & " (H) by " & PointsToInches(.PageWidth) & " (W) in inches"
End With
End Sub


Paul

NicoleJones
12-11-2011, 03:58 PM
Sorry Paul, I dont think I am expalining myself correctly. I need the document to look at the system that it is opened up in to to find out what papersizing it should be.

I am creating the Normal.dotm in Australia, so the papersize is automatically going to be A4 (because that is what my printer settings are). It is this Normal.dotm that will be rolled out around the world to all of our other offices. So when a new document opens I want it to look at the printer settings and automatically change the size, eg if it is oppened in America, it will look at the printer settings and see that the papersizing is Letter and then automatically change the new document sizing accordingly.

I hope this helps

NJ

Paul_Hossler
12-11-2011, 07:24 PM
I was afraid you were going to say that

I think the issue will be that the page layout settings in the document will determine how it wants to print. So if I write a document with US 8.5x11" and email it to someone in Queensland, the document will (AFAIK) still be 'set' to 8.5x11.

An API would probably be able to 'read' the current printer settings

Have you thought about reading the Window Regional Settings to find out the country and configure accordingly? For example, the WhereAmI sub belows returns 'United States' for my current WRS. There is also a 'Paper Size' option, but I don't know if it works on all versions of Windows, or even if it means what I think it might mean


Option Explicit
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As Long

'See http://msdn.microsoft.com/en-us/library/dd373739(v=VS.85).aspx for meaning of various constants.
Public Const LOCALE_USER_DEFAULT As Long = &H400
Public Const LOCALE_SENGLANGUAGE As Long = &H1001 ' English name of language
Public Const LOCALE_SENGCOUNTRY As Long = &H1002 ' English name of country
Public Const LOCALE_ILANGUAGE As Long = &H1
Public Const LOCALE_SLANGUAGE As Long = &H2
Public Const LOCALE_SABBREVLANGNAME As Long = &H3
Public Const LOCALE_SNATIVELANGNAME As Long = &H4 ' native name of language
Public Const LOCALE_ICOUNTRY As Long = &H5
Public Const LOCALE_SCOUNTRY As Long = &H6
Public Const LOCALE_SABBREVCTRYNAME As Long = &H7
Public Const LOCALE_SNATIVECTRYNAME As Long = &H8 ' native name of country
Public Const LOCALE_IDEFAULTLANGUAGE As Long = &H9
Public Const LOCALE_IDEFAULTCOUNTRY As Long = &HA
Public Const LOCALE_IDEFAULTCODEPAGE As Long = &HB
Public Const LOCALE_SLIST = &HC
Public Const LOCALE_IMEASURE As Long = &HD
Public Const LOCALE_SDECIMAL As Long = &HE
Public Const LOCALE_STHOUSAND As Long = &HF
Public Const LOCALE_SGROUPING As Long = &H10
Public Const LOCALE_IDIGITS As Long = &H11
Public Const LOCALE_ILZERO As Long = &H12
Public Const LOCALE_SNATIVEDIGITS As Long = &H13
Public Const LOCALE_SCURRENCY As Long = &H14 'local currency symbol
Public Const LOCALE_SINTLSYMBOL As Long = &H15 'intl symbol
Public Const LOCALE_SMONDECIMALSEP As Long = &H16 'decimal separator
Public Const LOCALE_SMONTHOUSANDSEP As Long = &H17 'thousand separator
Public Const LOCALE_SMONGROUPING As Long = &H18 'grouping
Public Const LOCALE_ICURRDIGITS As Long = &H19 '# local digits
Public Const LOCALE_IINTLCURRDIGITS As Long = &H1A '# intl digits
Public Const LOCALE_ICURRENCY As Long = &H1B 'pos currency mode
Public Const LOCALE_INEGCURR As Long = &H1C 'neg currency mode
Public Const LOCALE_SDATE As Long = &H1D
Public Const LOCALE_STIME As Long = &H1E
Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_SLONGDATE As Long = &H20
Public Const LOCALE_IDATE As Long = &H21
Public Const LOCALE_ILDATE As Long = &H22
Public Const LOCALE_ITIME As Long = &H23
Public Const LOCALE_ICENTURY As Long = &H24
Public Const LOCALE_ITLZERO As Long = &H25
Public Const LOCALE_IDAYLZERO As Long = &H26
Public Const LOCALE_IMONLZERO As Long = &H27
Public Const LOCALE_S1159 As Long = &H28
Public Const LOCALE_S2359 As Long = &H29
Public Const LOCALE_SDAYNAME1 As Long = &H2A 'long name for Monday
Public Const LOCALE_SDAYNAME2 As Long = &H2B 'long name for Tuesday
Public Const LOCALE_SDAYNAME3 As Long = &H2C 'long name for Wednesday
Public Const LOCALE_SDAYNAME4 As Long = &H2D 'long name for Thursday
Public Const LOCALE_SDAYNAME5 As Long = &H2E 'long name for Friday
Public Const LOCALE_SDAYNAME6 As Long = &H2F 'long name for Saturday
Public Const LOCALE_SDAYNAME7 As Long = &H30 'long name for Sunday
Public Const LOCALE_SABBREVDAYNAME1 As Long = &H31 'short name for Monday
Public Const LOCALE_SABBREVDAYNAME2 As Long = &H32 'short name for Tuesday
Public Const LOCALE_SABBREVDAYNAME3 As Long = &H33 'short name for Wednesday
Public Const LOCALE_SABBREVDAYNAME4 As Long = &H34 'short name for Thursday
Public Const LOCALE_SABBREVDAYNAME5 As Long = &H35 'short name for Friday
Public Const LOCALE_SABBREVDAYNAME6 As Long = &H36 'short name for Saturday
Public Const LOCALE_SABBREVDAYNAME7 As Long = &H37 'short name for Sunday
Public Const LOCALE_SMONTHNAME1 As Long = &H38
Public Const LOCALE_SMONTHNAME2 As Long = &H39
Public Const LOCALE_SMONTHNAME3 As Long = &H3A
Public Const LOCALE_SMONTHNAME4 As Long = &H3B
Public Const LOCALE_SMONTHNAME5 As Long = &H3C
Public Const LOCALE_SMONTHNAME6 As Long = &H3D
Public Const LOCALE_SMONTHNAME7 As Long = &H3E
Public Const LOCALE_SMONTHNAME8 As Long = &H3F
Public Const LOCALE_SMONTHNAME9 As Long = &H40
Public Const LOCALE_SMONTHNAME10 As Long = &H41
Public Const LOCALE_SMONTHNAME11 As Long = &H42
Public Const LOCALE_SMONTHNAME12 As Long = &H43
Public Const LOCALE_SABBREVMONTHNAME1 As Long = &H44
Public Const LOCALE_SABBREVMONTHNAME2 As Long = &H45
Public Const LOCALE_SABBREVMONTHNAME3 As Long = &H46
Public Const LOCALE_SABBREVMONTHNAME4 As Long = &H47
Public Const LOCALE_SABBREVMONTHNAME5 As Long = &H48
Public Const LOCALE_SABBREVMONTHNAME6 As Long = &H49
Public Const LOCALE_SABBREVMONTHNAME7 As Long = &H4A
Public Const LOCALE_SABBREVMONTHNAME8 As Long = &H4B
Public Const LOCALE_SABBREVMONTHNAME9 As Long = &H4C
Public Const LOCALE_SABBREVMONTHNAME10 As Long = &H4D
Public Const LOCALE_SABBREVMONTHNAME11 As Long = &H4E
Public Const LOCALE_SABBREVMONTHNAME12 As Long = &H4F
Public Const LOCALE_SPOSITIVESIGN As Long = &H50
Public Const LOCALE_SNEGATIVESIGN As Long = &H51
Public Const LOCALE_IPOSSIGNPOSN As Long = &H52 'pos sign position
Public Const LOCALE_INEGSIGNPOSN As Long = &H53 'neg sign position
Public Const LOCALE_IPOSSYMPRECEDES As Long = &H54 'mon sym precedes pos amt
Public Const LOCALE_IPOSSEPBYSPACE As Long = &H55 'mon sym sep by space from pos amt
Public Const LOCALE_INEGSYMPRECEDES As Long = &H56 'mon sym precedes neg amt
Public Const LOCALE_INEGSEPBYSPACE As Long = &H57 'mon sym sep by space from neg amt
Public Const LOCALE_FONTSIGNATURE As Long = &H58
Public Const LOCALE_SISO639LANGNAME As Long = &H59
Public Const LOCALE_SISO3166CTRYNAME As Long = &H5A
Public Const LOCALE_IGEOID As Long = &H5B
Public Const LOCALE_SNAME As Long = &H5C
Public Const LOCALE_SDURATION As Long = &H5D
Public Const LOCALE_SKEYBOARDSTOINSTALL = &H5E
'**
Public Const LOCALE_SSHORTESTDAYNAME1 As Long = &H60
Public Const LOCALE_SSHORTESTDAYNAME2 As Long = &H61
Public Const LOCALE_SSHORTESTDAYNAME3 As Long = &H62
Public Const LOCALE_SSHORTESTDAYNAME4 As Long = &H63
Public Const LOCALE_SSHORTESTDAYNAME5 As Long = &H64
Public Const LOCALE_SSHORTESTDAYNAME6 As Long = &H65
Public Const LOCALE_SSHORTESTDAYNAME7 As Long = &H66
Public Const LOCALE_SISO639LANGNAME2 As Long = &H67
Public Const LOCALE_SISO3166CTRYNAME2 As Long = &H68
Public Const LOCALE_SNAN As Long = &H69
Public Const LOCALE_SPOSINFINITY As Long = &H6A
Public Const LOCALE_SNEGINFINITY As Long = &H6B
Public Const LOCALE_SSCRIPTS As Long = &H6C
Public Const LOCALE_SPARENT As Long = &H6D
Public Const LOCALE_SCONSOLEFALLBACKNAME As Long = &H6E
'**
Public Const LOCALE_IREADINGLAYOUT As Long = &H70
Public Const LOCALE_INEUTRAL As Long = &H71
'**
Public Const LOCALE_INEGATIVEPERCENT As Long = &H74
Public Const LOCALE_IPOSITIVEPERCENT As Long = &H75
Public Const LOCALE_SPERCENT As Long = &H76
Public Const LOCALE_SPERMILLE As Long = &H77
Public Const LOCALE_SMONTHDAY As Long = &H78
Public Const LOCALE_SSHORTTIME As Long = &H79
Public Const LOCALE_SOPENTYPELANGUAGETAG As Long = &H7A
Public Const LOCALE_SSORTLOCALE As Long = &H7B
Public Const LOCALE_STIMEFORMAT As Long = &H1003
Public Const LOCALE_IDEFAULTANSICODEPAGE As Long = &H1004
Public Const LOCALE_ITIMEMARKPOSN As Long = &H1005
Public Const LOCALE_SYEARMONTH As Long = &H1006
Public Const LOCALE_SENGCURRNAME As Long = &H1007 'english name of currency
Public Const LOCALE_SNATIVECURRNAME As Long = &H1008 'native name of currency
Public Const LOCALE_ICALENDARTYPE As Long = &H1009
Public Const LOCALE_IPAPERSIZE As Long = &H100A
Public Const LOCALE_IOPTIONALCALENDAR As Long = &H100B
Public Const LOCALE_IFIRSTDAYOFWEEK As Long = &H100C
Public Const LOCALE_IFIRSTWEEKOFYEAR As Long = &H100D
Public Const LOCALE_SMONTHNAME13 As Long = &H100E
Public Const LOCALE_SABBREVMONTHNAME13 As Long = &H100F
Public Const LOCALE_INEGNUMBER As Long = &H1010
Public Const LOCALE_IDEFAULTMACCODEPAGE As Long = &H1011
Public Const LOCALE_IDEFAULTEBCDICCODEPAGE As Long = &H1012
Public Const LOCALE_SSORTNAME As Long = &H1013
Public Const LOCALE_IDIGITSUBSTITUTION As Long = &H1014
Public Function GetInfo(ByVal lInfo As Long) As String
Dim Buffer As String
Dim Ret As String
Buffer = String$(256, 0)
Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, Buffer, Len(Buffer))
If Ret > 0 Then
GetInfo = Left$(Buffer, Ret - 1)
Else
GetInfo = ""
End If
lbl_Exit:
Exit Function
End Function

Sub WhereAmI()
MsgBox GetInfo(LOCALE_SNATIVECTRYNAME)
End Sub



Paul

NicoleJones
12-11-2011, 09:19 PM
Hi Paul

I could kiss you right now!

Thank you, thank you, thank you

You have just cured my 2 month head ache. I love your work.:bow:

NJ:beerchug:

Paul_Hossler
12-13-2011, 07:16 PM
Ah shucks

I took the code from Greg (below) and incorporated it into my toolbox workbook where I keep all the neat and nifty things I run accross

http://www.vbaexpress.com/forum/showthread.php?t=38856

I just tried to generalize it as I build my 'library'


Greg has a good site, and is a very useful resource here in the forums

Hope it helps

Paul