Results 1 to 14 of 14

Macro to export to pdf

Threaded View

  1. #1
    Registered User
    Join Date
    08-04-2012
    Location
    cardiff
    MS-Off Ver
    Excel 2007
    Posts
    49

    Macro to export to pdf

    I have a workbook that calculates times based on certain start time, schedules etc and then using a macro designed sometime ago by a colleague prints all the selected sheets to the default printer - say from rider 1 (lowest number) to rider 10 (highest number) but could be up to 500 sheets, however I would like to amend the macro so it exports the data in one file in a pdf, I've tried just changing the default printer to the microsoft pdf option but that then requires me to name each rider page separately and I'd like them all in one folder to be able to email over - any help would be appreciated I've pasted the code I have below

    Thanks



     Sub PrintCards()
    ' PrintCards Macro
    ' Macro recorded 29/06/2002 by
    ' Keyboard Shortcut: Ctrl+P
    
    
    
    Dim RiderNum As Long, HighestNumber As Long, classnum As Long, RowNumb As Long
    Dim strNumber As String, ValidRider As Boolean
    'RiderNum = 1
    'set timecard section for print area output
        ActiveSheet.PageSetup.PrintArea = "$Ak$41:$bg$72"
    
    'set printer page orientation to landscape
    Worksheets("Sheet1").PageSetup.Orientation = xlLandscape
    
    'turn error capture on
    On Error GoTo catcherror
    
    'get the first Rider Number to print times for
    strNumber = InputBox("Enter The First Rider Number for to Print Times for. ", "Timecard Generator,")
    RiderNum = Val(strNumber)
    
    'Get the highest Number to be printed.
    strNumber = InputBox("Enter The Highest Rider Number to Print Times for. ", "Timecard Generator,")
    HighestNumber = Val(strNumber)
    
    FindRiderNum:
     
     
     'do a loop to keep prog running until HighestNumber
    Do While RiderNum <= HighestNumber
    
    
    
    'ValidRider = True
    
            With Sheet1.Range("a15:a3000")
                Cells.Find(RiderNum, , LookIn:=xlValues, LookAt:= _
                xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False).Activate
            End With
            
                
        If ActiveCell.Column = 1 Then 'And ValidRider = True Then
            RiderNum = RiderNum + 1
      
        
        
    'put a printed logo in line with riders details
            ActiveCell.Offset(0, 6).Select
            ActiveCell.Value = "Printed."
            ActiveCell.Offset(0, -6).Select
            
    
    'highlight details ready for copy
            Range(ActiveCell, ActiveCell.Offset(0, 5)).Select
    
    'copy to clipboard
            Selection.Copy
            Range("A8").Select
    
    'paste into A8
            ActiveSheet.Paste
            Application.CutCopyMode = False
    
    'get class number of this rider
        Range("f8").Select
        classnum = ActiveCell.Value
    
    'work out position of Class Schedule
    
    RowNumb = 9 + (classnum * 7)
    
    'Get the correct class schedule and move it to Range m15
    
    Range(ActiveCell.Offset(RowNumb, 7), ActiveCell.Offset(RowNumb + 5, 26)).Select
    
    'copy to clipboard
            Selection.Copy
    
    'select Schedule area
    Range("m15").Select
    
    'paste into Schedules area (L15)
            ActiveSheet.Paste
            Application.CutCopyMode = False
    
    'send timecards to printer
          ActiveWindow.allSheets.PrintOut Copies:=1, PrintTofile:=True, Preview:=False, Collate:=True
    
    'clear the pasted entry and class time schedule
    
        Range("a8:f8").Select
        Selection.ClearContents
        Range("M15:af20").Select
        Selection.ClearContents
        Range("a15").Select
    
    Else: RiderNum = RiderNum + 1
    End If
    
    'to keep timecard prog running
    
    Loop
    ActiveWorkbook.Save
    ActiveWorkbook.Application.Quit
    
    End
    
    
    catcherror:
    
    'number not found error
             'ValidRider = False
            RiderNum = RiderNum + 1
            Resume FindRiderNum
    
    
        End Sub
    Last edited by suedavies; 05-16-2016 at 11:31 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to export and import a module and assigning different macro automatically
    By Libster78 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-14-2015, 06:31 PM
  2. Macro to Export a Sheet but also export a macro?
    By ChrisF79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2013, 12:26 PM
  3. I would need a macro to export data from base example workbook to export worbook
    By slato8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:21 AM
  4. Help with an export macro
    By iisjman07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2011, 01:35 PM
  5. Export XML via a macro
    By DangerMouse in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2006, 08:37 AM
  6. export to csv macro
    By PM4 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2006, 04:30 PM
  7. Macro to Export XML
    By DangerMouse in forum Excel General
    Replies: 1
    Last Post: 04-10-2006, 09:49 AM
  8. Export CSV Macro
    By g.wattel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-14-2005, 10:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1