PDA

View Full Version : Solved: Opening a window to the active.path location



andrewvanmar
07-11-2007, 02:34 AM
Hi all,

I'm trying to refine a script that charlize kindly helped me to use (http://vbaexpress.com/forum/showthread.php?p=103492#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?

RichardSchollar
07-11-2007, 02:50 AM
Hi

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

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

Richard

Charlize
07-11-2007, 02:59 AM
Hi all,

I'm trying to refine a script that charlize kindly helped me to use (http://vbaexpress.com/forum/showthread.php?p=103492#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.

andrewvanmar
07-11-2007, 03:52 AM
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

Private Sub PDFbutton_Click()
'Author : Ken Puls (www.excelguru.ca (http://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

andrewvanmar
07-11-2007, 04:21 AM
@ charlize, sorry missed that in the previous thread, guess I need to read more carefully :(

andrewvanmar
07-11-2007, 04:34 AM
moving the discussion back to (http://vbaexpress.com/forum/showthread.php?p=103492#post103492)