hi im new to vb.net
I would like to obtain the current selections page orientation
so i can then set the new orientation either portrait or landscape, and apply the appropriate formatting
in vb.net how would i define and obtain the current page orientation?
heres the code in vba...
Dim x
x = Selection.PageSetup.Orientation
if x = landscape
apply correct formatting here
elseif x = potrairt
apply correct formatting here
endif
thank you
diana
vb.net newbie - how do i define and obtain page setup orient
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
vb.net newbie - how do i define and obtain page setup orient
Last edited by diana on 04 Aug 2010, 06:04, edited 1 time in total.
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
thank you all
i worked it out...
Dim CurrentOrienation As String
CurrentOrienation = CStr(wordDoc.Document.Application.Selection.PageSetup.Orientation)
i worked it out...
Dim CurrentOrienation As String
CurrentOrienation = CStr(wordDoc.Document.Application.Selection.PageSetup.Orientation)
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
oops...actually i havent worked it out...i still need a hand pls
the value returned is incorrect
if its portrait the valuereturns '0'
or if its landscape the value returned is '0'
thank you
the value returned is incorrect
if its portrait the valuereturns '0'
or if its landscape the value returned is '0'
thank you
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vb.net newbie - how do i define and obtain page setup orient
Are you sure that '0' is returned for Landscape?
How is the variable wordDoc declared and assigned?
How is the variable wordDoc declared and assigned?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
i think my declaration is incorrect..
ive tried both...
Dim currentOrient As Single
currentOrient = wordDoc.Document.Application.Selection.PageSetup.Orientation
currentOrient = CSng(CStr(wordDoc.Document.Application.Selection.PageSetup.Orientation))
MsgBox(currentOrient)
'portrait
If currentOrient = 0 Then
CurrentOrienation = "portrait"
'landscape
ElseIf currentOrient = 1 Then
CurrentOrienation = "landscape"
End If
ive tried both...
Dim currentOrient As Single
currentOrient = wordDoc.Document.Application.Selection.PageSetup.Orientation
currentOrient = CSng(CStr(wordDoc.Document.Application.Selection.PageSetup.Orientation))
MsgBox(currentOrient)
'portrait
If currentOrient = 0 Then
CurrentOrienation = "portrait"
'landscape
ElseIf currentOrient = 1 Then
CurrentOrienation = "landscape"
End If
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vb.net newbie - how do i define and obtain page setup orient
Does the message box display 0 for both landscape and portrait sections?
Again, how is wordDoc declared and how do you set it?
Again, how is wordDoc declared and how do you set it?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
yes the message box displays 0 for landscape and 0 for portrait orientation.
i think thats my issue i dont know how to define and declare in vb.net
Public Shared Sub SetAdviceHeading(ByVal adviceheading As AdviceHeading, ByVal wordDoc As WordDocument)
i think thats my issue i dont know how to define and declare in vb.net
Public Shared Sub SetAdviceHeading(ByVal adviceheading As AdviceHeading, ByVal wordDoc As WordDocument)
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vb.net newbie - how do i define and obtain page setup orient
How do you call SetAdviceHeading, i.e. what do you pass as arguments?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
Dim m_documentBaseAdviceHeading As DocumentBaseForAdviceHeading = CType(m_AdvicePart, DocumentBaseForAdviceHeading)
AdviceHeadingController.SetAdviceHeading(m_documentBaseAdviceHeading.AdviceHeading, m_library.ActiveDocument)
AdviceHeadingController.SetAdviceHeading(m_documentBaseAdviceHeading.AdviceHeading, m_library.ActiveDocument)
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vb.net newbie - how do i define and obtain page setup orient
Thanks. Does this work?
Dim currentOrient As Int16
currentOrient = wordDoc.Application.Selection.Orientation
You might also try
currentOrient = wordDoc.ActiveWindow.Selection.Orientation
Dim currentOrient As Int16
currentOrient = wordDoc.Application.Selection.Orientation
You might also try
currentOrient = wordDoc.ActiveWindow.Selection.Orientation
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
thanks Hans
Ive tried your suggestion thankyou. I also applied the following...
Dim currentOrient As Int16
Dim currentOrient As Single = Nothing
selection.Collapse(MSWord.WdCollapseDirection.wdCollapseEnd)
currentOrient = wordDoc.Document.Application.Selection.PageSetup.Orientation
For both portrait and landscape returns 0.
do you think its another declaration?
diana
ps. for something that appears so simple is not so :o
Ive tried your suggestion thankyou. I also applied the following...
Dim currentOrient As Int16
Dim currentOrient As Single = Nothing
selection.Collapse(MSWord.WdCollapseDirection.wdCollapseEnd)
currentOrient = wordDoc.Document.Application.Selection.PageSetup.Orientation
For both portrait and landscape returns 0.
do you think its another declaration?
diana
ps. for something that appears so simple is not so :o
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: vb.net newbie - how do i define and obtain page setup orient
currentOrient = wordDoc.Document.Application.Selection.PageSetup.Orientation
doesn't look correct to me, since wordDoc is already a document. I think it should be
currentOrient = wordDoc.Application.Selection.PageSetup.Orientation
And you should not declare currentOrient as a Single, for Orientation is not a floating point value (with decimal places) but a whole number. That's why I suggested declaring it as Int16.
Perhaps it would be easier to develop working code within Word, then convert it to VB.Net. Starting in VB.Net from scratch is harder.
doesn't look correct to me, since wordDoc is already a document. I think it should be
currentOrient = wordDoc.Application.Selection.PageSetup.Orientation
And you should not declare currentOrient as a Single, for Orientation is not a floating point value (with decimal places) but a whole number. That's why I suggested declaring it as Int16.
Perhaps it would be easier to develop working code within Word, then convert it to VB.Net. Starting in VB.Net from scratch is harder.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 279
- Joined: 01 Jun 2010, 00:27
Re: vb.net newbie - how do i define and obtain page setup orient
the following worked....
Dim currentOrient As Int16
selection.Collapse(MSWord.WdCollapseDirection.wdCollapseEnd)
currentOrient = CShort(wordDoc.Document.Application.Selection.PageSetup.Orientation)
MsgBox(currentOrient)
for portrait returns a value of 0
for landscape returns a value of 1
thanks again for your help Hans
ps. your right vb.net is hard
i did create my working code in vba.
when i use the VSS tool "upgrade Visual Basic 6 Code...
the result is it always errors. perhaps im not running the tool right.
then i manually convert my vba code to vb.net - currently it just takes me awhile eg the orientation
Dim currentOrient As Int16
selection.Collapse(MSWord.WdCollapseDirection.wdCollapseEnd)
currentOrient = CShort(wordDoc.Document.Application.Selection.PageSetup.Orientation)
MsgBox(currentOrient)
for portrait returns a value of 0
for landscape returns a value of 1
thanks again for your help Hans
ps. your right vb.net is hard
i did create my working code in vba.
when i use the VSS tool "upgrade Visual Basic 6 Code...
the result is it always errors. perhaps im not running the tool right.
then i manually convert my vba code to vb.net - currently it just takes me awhile eg the orientation