Solved

Print Area in excel from vb6 form

Posted on 2004-10-19
5
1,028 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
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
ampapa earned 400 total points
Comment Utility
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
Comment Utility
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 33

Author Comment

by:Mike Eghtebas
Comment Utility

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

Assisted Solution

by:craigewens
craigewens earned 100 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now