?
Solved

Print Area in excel from vb6 form

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

743 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