Consulting

Results 1 to 6 of 6

Thread: Solved: Opening a window to the active.path location

  1. #1

    Solved: Opening a window to the active.path location

    Hi all,

    I'm trying to refine a script that charlize kindly helped me to use (http://vbaexpress.com/forum/showthre...492#post103492)

    it creates a pdf of the workbook, and saves it in the location where the workbook is saved. What I'd like the script to do after all this is open an explorer window to the active.path location.

    is that possible?

  2. #2
    VBAX Contributor
    Joined
    Aug 2006
    Location
    Hampshire, UK
    Posts
    140
    Location
    Hi

    Here's some sample code that will open Windows Explorer at the path of the activeworkbook (which can obviously be modified):

    [VBA]Sub Open_Explorer()
    Dim retVal
    On Error Resume Next
    retVal = Shell("explorer.exe " & ActiveWorkbook.Path, vbNormalFocus)
    End Sub[/VBA]

    Richard

  3. #3
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,284
    Location
    Quote Originally Posted by andrewvanmar
    Hi all,

    I'm trying to refine a script that charlize kindly helped me to use (http://vbaexpress.com/forum/showthre...492#post103492)

    it creates a pdf of the workbook, and saves it in the location where the workbook is saved. What I'd like the script to do after all this is open an explorer window to the active.path location.

    is that possible?
    Yes, read the complete thread. I gave you two possibilities for that. One in a workbook and one in coding.

  4. #4
    Thanks!

    Just pasting it in doesn't work though, ( i wanted to place it before the end sub, but I got an expected end error

    [VBA]Private Sub PDFbutton_Click()
    'Author : Ken Puls (www.excelguru.ca)
    'Macro Purpose: Print to PDF file using PDFCreator
    ' (Download from http://sourceforge.net/projects/pdfcreator/)
    ' Designed for early bind, set reference to PDFCreator
    '
    'Adapted by Charlize for printing certain worksheets (15/06/2007)
    Dim pdfjob As PDFCreator.clsPDFCreator
    Dim sPDFName As String
    Dim sPDFPath As String
    Dim lSheet As Long
    Dim lTtlSheets As Long
    '/// Change the output file name here! ///
    sPDFName = ActiveWorkbook.Name
    ' "Consolidated.pdf"
    sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
    Set pdfjob = New PDFCreator.clsPDFCreator
    'Make sure the PDF printer can start
    If pdfjob.cStart("/NoProcessingAtStartup") = False Then
    MsgBox "Can't initialize PDFCreator.", vbCritical + _
    vbOKOnly, "Error!"
    Exit Sub
    End If
    'Set all defaults
    With pdfjob
    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    .cOption("AutosaveDirectory") = sPDFPath
    .cOption("AutosaveFilename") = sPDFName
    .cOption("AutosaveFormat") = 0 ' 0 = PDF
    .cClearCache
    End With
    'Print the document to PDF
    lTtlSheets = Application.Sheets.Count
    For lSheet = 1 To Application.Sheets.Count
    On Error Resume Next 'To deal with chart sheets
    If Sheets(lSheet).Name = "Information" Or _
    Sheets(lSheet).Name = "IPL Service" Or _
    Sheets(lSheet).Name = "Signatures and pricing" Then
    If Not IsEmpty(Application.Sheets(lSheet).UsedRange) Then
    Application.Sheets(lSheet).PrintOut copies:=1, ActivePrinter:="PDFCreator"
    Application.Wait (Now + TimeValue("0:00:05"))
    Else
    lTtlSheets = lTtlSheets - 1
    End If
    Else
    lTtlSheets = lTtlSheets - 1
    End If
    On Error GoTo 0
    Next lSheet
    'Wait until all print jobs have entered the print queue
    Do Until pdfjob.cCountOfPrintjobs = lTtlSheets
    DoEvents
    Loop
    'Combine all PDFs into a single file and stop the printer
    With pdfjob
    .cCombineAll
    .cPrinterStop = False
    End With
    'Wait until PDF creator is finished then release the objects
    Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
    Loop
    Application.Wait (Now + TimeValue("0:00:05"))
    pdfjob.cClose
    Set pdfjob = Nothing
    MsgBox "PDF File successfully created.", vbInformation, "PDF creation ..."

    'Open a window with the pdf location
    Sub Open_Explorer()
    Dim retVal
    On Error Resume Next
    retVal = Shell("explorer.exe " & ActiveWorkbook.Path, vbNormalFocus)
    End Sub[/VBA]

  5. #5
    @ charlize, sorry missed that in the previous thread, guess I need to read more carefully

  6. #6

Posting Permissions

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