Results 1 to 5 of 5

Creating an Array using Loops

Threaded View

lee2k60 Creating an Array using Loops 07-09-2010, 09:40 AM
Andy Pope Re: Creating an Array using... 07-09-2010, 09:51 AM
snb Re: Creating an Array using... 07-09-2010, 09:51 AM
lee2k60 Re: Creating an Array using... 07-09-2010, 10:10 AM
lee2k60 Re: Creating an Array using... 07-09-2010, 10:25 AM
  1. #1
    Registered User
    Join Date
    06-04-2010
    Location
    Bolton, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Thumbs up Creating an Array using Loops

    Hi all,

    I was wondering if anyone could assist me with my code. The reason I have structured it in such a way, is that I want the end user to be able to make amendments to the criteria hosted on a work sheet.

    Sub PrintToPDF_Early()
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
        
    Dim thisBook As String
    Dim pdfjob As PDFCreator.clsPDFCreator
    Dim targetPath As String
    Dim targetName As String
    Dim targetSheet As String
    Dim targetPrint As String
    Dim x As String
    
    thisBook = ActiveWorkbook.Name
    
    Windows(thisBook).Activate
    
    targetPath = Range("TargetFilepath").Text
    targetName = Range("TargetFilename").Text
    
    For Each Cell In Range("SheetsToPrint")
    
    targetSheet = Cell.Value & """"
    
    x = x & targetSheet & ","""
    
    Next Cell
    
    targetPrint = Left(x, Len(x) - 2)
    
    'Check if worksheet is empty and exit if so
    If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
    
    Set pdfjob = New PDFCreator.clsPDFCreator
    
    With pdfjob
        If .cStart("/NoProcessingAtStartup") = False Then
                MsgBox "Can't initialize PDFCreator.", vbCritical + _
                        vbOKOnly, "PrtPDFCreator"
                
        Exit Sub
        End If
            .cOption("UseAutosave") = 1
            .cOption("UseAutosaveDirectory") = 1
            .cOption("AutosaveDirectory") = targetPath
            .cOption("AutosaveFilename") = targetName
            .cOption("AutosaveFormat") = 0    ' 0 = PDF
            .cClearCache
        End With
    
    MsgBox targetPrint
    
    'Print the document to PDF
    Sheets(Array(targetPrint)).PrintOut copies:=1, ActivePrinter:="PDFCreator"
    
    'Wait until the print job has entered the print queue
    Do Until pdfjob.cCountOfPrintjobs = 1
            DoEvents
    Loop
    pdfjob.cPrinterStop = False
    
    'Wait until PDF creator is finished then release the objects
    Do Until pdfjob.cCountOfPrintjobs = 0
        DoEvents
    Loop
    pdfjob.cClose
    Set pdfjob = Nothing
    
    End Sub
    I'm having real trouble with the declaration of the "TargetPrint", there are too many quotation marks, meaning the code can't recognise.

    Anyone have any idea's how I can overcome this problem?

    Thanks!
    Last edited by lee2k60; 07-09-2010 at 10:25 AM.

Thread Information

Users Browsing this Thread

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

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