Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2006, 09:29 AM
Authorized User
 
Join Date: Apr 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default print/save functions and error message

I'm having a problem getting the print, save and error handling working properly in my form. The combination of print and save are contingent on the error handling. Once the combobox is changed, the code filters the spreadsheet by the value of the combobox. It then checks to see if there are any filled in rows and if there are not it should create an error and exit. That part is not working correctly. The other part is the print/save. If there are filled in rows, I want the code to print the rows and save them in a seperate workbook using the OrgShp value as part of the saved filename - which it should overwrite anytime you filter without asking for overwrite permission. Any help will be greatly appreciated. Here's the code:

Private Sub cboOrgShpFilterExp_Change()
Dim Expenditures As Range
Dim NewWorkbook As Workbook
Dim WorksheetName As Variant
Dim OrgShp As String
Dim TempWorkbook As Workbook

OrgShp = cboOrgShpFilterExp.Value
    On Error Resume Next
        WorksheetName = Format( _
            DateValue(OrgShp & " "), "ddmmmyyyy")

    Set TempWorkbook = Workbooks(WorksheetName)

    With Range("expenditures")
        .AutoFilter field:=2, Criteria1:=(OrgShp), VisibleDropDown:=False
            On Error Resume Next
                MsgBox "There are no expenditures to report for this Org/Shop"
                Call Unload(Me)
    Set NewWorkbook = Workbooks.Add
        .Copy Destination:=NewWorkbook.Range("B1")
    End With

NewWorkbook.Columns("A:H").AutoFit

ActiveSheet.Name = WorksheetName
With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .CenterHeader = "Expenditure Log" & Chr(10) & "&D"
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = False
        .Orientation = xlPortrait
        .Zoom = 100
    End With
    'ActiveSheet.PrintOut

  Set TempWorkbook = Workbooks.Add
    Application.DisplayAlerts = False
    Workbook1.SaveAs Filename:=ThisWorkbook.Path & "\" & (OrgShp.Value) & "Exp_log.xls"
    Application.DisplayAlerts = True


Call Unload(Me)

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
save outlook mail message Mohammad VB How-To 2 January 27th, 2011 04:55 AM
Word - Merge print/save mat41 Classic ASP Professional 0 October 26th, 2008 06:12 PM
Hiding Excel Print & Save Option Only p.muralikrishnaa VB Components 0 September 23rd, 2006 12:07 AM
Print Functions johnny_utah Access 3 April 23rd, 2006 06:56 PM
Get message from system "print" dialog box pavel Pro VB 6 0 August 28th, 2003 09:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.