Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Print Area in excel from vb6 form

Posted on 2004-10-19
5
Medium Priority
?
1,101 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 1600 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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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