Solved

Print Area in excel from vb6 form

Posted on 2004-10-19
5
1,056 Views
Last Modified: 2010-05-18
I am opening an excel file from a vb 6 form.  I want code to do foolowing:

1. Determine if there is a print area is set.
2. If there is no print area, locate the last cell(s) and set a print area.
2. Change View/Normal setting to View/Page Break Review.

Thanks
0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
ampapa earned 400 total points
ID: 12354244
I think this will work.

Public Sub SetPA()

Dim ws As Worksheet
Dim pa As String

Set ws = ActiveSheet
pa = ActiveSheet.PageSetup.PrintArea

If pa = "" Then

With ws.PageSetup
 .PrintArea = ws.UsedRange.Address
End With

End If

End Sub
0
 
LVL 8

Expert Comment

by:ampapa
ID: 12354353
Moving to VB....

Private Sub SetPA()
Dim xlApp As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Set xlApp = CreateObject("Excel.application")
Dim pa As String

Set wb = xlApp.Workbooks.open("filename")
Set ws = wb.ActiveSheet
pa = ws.PageSetup.PrintArea

If pa = "" Then

With ws.PageSetup
 .PrintArea = ws.UsedRange.Address
End With

End If

Set ws = Nothing
Set wb = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12354949

How about: <3. Change View/Normal setting to View/Page Break Review.>
0
 
LVL 2

Assisted Solution

by:craigewens
craigewens earned 100 total points
ID: 12355868
ActiveWindow.View = xlPageBreakPreview

or

for ampapa's VB version


Private Sub SetPA()
Dim xlApp As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Set xlApp = CreateObject("Excel.application")
Dim pa As String

Set wb = xlApp.Workbooks.open("filename")
Set ws = wb.ActiveSheet

-------------------
ws.view = xlPageBreakPreview
-------------------

pa = ws.PageSetup.PrintArea

If pa = "" Then

With ws.PageSetup
 .PrintArea = ws.UsedRange.Address
End With

End If

Set ws = Nothing
Set wb = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub
0
 
LVL 8

Expert Comment

by:ampapa
ID: 12356678
ActiveWindow.View = xlPageBreakPreview
ActiveWindow.View = xlNormalView


Private Sub SetPA()
Dim xlApp As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Set xlApp = CreateObject("Excel.application")
Dim pa As String

Set wb = xlApp.Workbooks.open("filename")
Set ws = wb.ActiveSheet
pa = ws.PageSetup.PrintArea

If pa = "" Then

With ws.PageSetup
 .PrintArea = ws.UsedRange.Address
End With

End If

ActiveWindow.View = xlPageBreakPreview

Set ws = Nothing
Set wb = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 41
vb6 connector to mongodb 2 144
Visual Studio search word table and return Cell index 8 78
VB6 - Convert HH:MM into Decimal 8 70
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question