If Then Else Statement

D

Diamonds_Mine

I need some input on a piece of code. I have information being pulled from
an *.ini file that will make certain changes in the header and footer of the
document if "A4" is the paper size; the code is below. However, this code
does not work if the Word language is set to German because the words
"Header" and "Footer" are different (they are "Kopfzeile" and "Fußzeile").
So I need to know how to have the macro also recognize if Word is using the
German language and tell it to run the same code. Any assistance you can
provide is greatly appreciated. Thank you.

'set A4 paper size for International Offices (also change tabs in Headers
and Footers)
strPaper = System.PrivateProfileString(strOfficeFile, strOffice, "Paper")
If strPaper = "A4" Then
ActiveDocument.PageSetup.PaperSize = wdPaperA4
ActiveDocument.Styles("Header").ParagraphFormat.TabStops.ClearAll
ActiveDocument.Styles("Header").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(2.89), Alignment:=wdAlignTabCenter, Leader:= _
wdTabLeaderSpaces
ActiveDocument.Styles("Header").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(5.75), Alignment:=wdAlignTabRight, Leader:= _
wdTabLeaderSpaces
ActiveDocument.Styles("Footer").ParagraphFormat.TabStops.ClearAll
ActiveDocument.Styles("Footer").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(2.89), Alignment:=wdAlignTabCenter, Leader:= _
wdTabLeaderSpaces
ActiveDocument.Styles("Footer").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(5.75), Alignment:=wdAlignTabRight, Leader:= _
wdTabLeaderSpaces
 
J

Jonathan West

Diamonds_Mine said:
I need some input on a piece of code. I have information being pulled from
an *.ini file that will make certain changes in the header and footer of
the
document if "A4" is the paper size; the code is below. However, this code
does not work if the Word language is set to German because the words
"Header" and "Footer" are different (they are "Kopfzeile" and "Fußzeile").
So I need to know how to have the macro also recognize if Word is using
the
German language and tell it to run the same code. Any assistance you can
provide is greatly appreciated. Thank you.

'set A4 paper size for International Offices (also change tabs in Headers
and Footers)
strPaper = System.PrivateProfileString(strOfficeFile, strOffice,
"Paper")
If strPaper = "A4" Then
ActiveDocument.PageSetup.PaperSize = wdPaperA4
ActiveDocument.Styles("Header").ParagraphFormat.TabStops.ClearAll
ActiveDocument.Styles("Header").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(2.89), Alignment:=wdAlignTabCenter, Leader:= _
wdTabLeaderSpaces
ActiveDocument.Styles("Header").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(5.75), Alignment:=wdAlignTabRight, Leader:= _
wdTabLeaderSpaces
ActiveDocument.Styles("Footer").ParagraphFormat.TabStops.ClearAll
ActiveDocument.Styles("Footer").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(2.89), Alignment:=wdAlignTabCenter, Leader:= _
wdTabLeaderSpaces
ActiveDocument.Styles("Footer").ParagraphFormat.TabStops.Add
Position:= _
InchesToPoints(5.75), Alignment:=wdAlignTabRight, Leader:= _
wdTabLeaderSpaces

Instead of using ActiveDocument.Styles("Header") and
ActiveDocument.Styles("Footer") use ActiveDocument.Styles(wdStyleHeader) and
ActiveDocument.Styles(wdStyleFooter) respectively. These will work in any
language version, so you do not need to worry about detecting the language.

But if you find you need to detect the language anyway, Application.Language
returns the language ID code for the version of Word you are using, and
Application.Languages(Application.Language) will return the associated
language name.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi

maybe

Application.International(wdProductLanguageID)

would be sufficient.

US-English 1033, German 1039.

Otherwise use error trapping.

HTH
--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Diamonds_Mine

Thank you so much Jonathan; that worked.

Jonathan West said:
Instead of using ActiveDocument.Styles("Header") and
ActiveDocument.Styles("Footer") use ActiveDocument.Styles(wdStyleHeader) and
ActiveDocument.Styles(wdStyleFooter) respectively. These will work in any
language version, so you do not need to worry about detecting the language.

But if you find you need to detect the language anyway, Application.Language
returns the language ID code for the version of Word you are using, and
Application.Languages(Application.Language) will return the associated
language name.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.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