LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Odd Export as PDF problem - Killing me.

I have the routine below in a number of workbooks. Typically it works
without a problem. I have a sheet with sheet names that I select and
it exports the sheets to a PDF. For some reason sometimes it only
produces a PDF with the first sheet in it instead of all sheetnames
that were selected.

I have made sure the sheetname array has more than one value and have
also made sure (by exiting before the export) that it is selecting the
correct sheets in a group. Both of those work fine. I have also made
sure that there was not a problem with the SortableDateString
fuction.

If I manually select the sheets (which is a pain in a book of 70 or
more sheets) export works fine - gives me all the sheets I have
selected.

It is like the file is in some state that is making exporting multiple
sheets a problem. I can open other workbooks with the same exact sub
in it and it will work fine.

Driving me crazy. Must be something too simple to see.

any help would be appreciated!

Sub PDFSet()
Dim c As Variant
Dim sName As String
Dim sh As Worksheet
Dim OrgSheet As String
Dim ExportFileName As String
Dim sheetnames() As String
Dim i As Integer
Dim DefaultFileName As String

i = 0
DefaultFileName = SortableDateString(Now())

OrgSheet = ActiveSheet.Name
ExportFileName = Application.GetSaveAsFilename(ActiveWorkbook.Name &
"." & DefaultFileName & ".pdf")

If ExportFileName = "" Then
'If ExportFileName = False Then ' was causing error so changed to zero
length string as test
End
End If

On Error GoTo er

For Each c In Selection

If Len(c.Value) 0 Then
ReDim Preserve sheetnames(i)
sheetnames(i) = c.Value
i = i + 1
End If
Next c

Sheets(sheetnames).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Documents and Settings\mgray\My Documents\xtemp
\junk1..pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True,
IgnorePrintAreas:=False, _
OpenAfterPublish:=True


'ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF,
Filename:=ExportFileName, Quality:= _
xlQualityStandard, IncludeDocProperties:=True,
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

Debug.Print "sheets to print " & UBound(sheetnames)

Sheets(OrgSheet).Select

er:
If err.Number = 9 Then
MsgBox "The Sheet named - " & sName & " - does not exist"
Resume Next
End If

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
This is killing me Michael Excel Programming 5 March 12th 08 09:07 PM
Simple problem for you all....killing me though [email protected] Excel Discussion (Misc queries) 5 July 16th 07 01:26 PM
Syntax or Something is KILLING Me Strong Eagle Excel Programming 5 July 2nd 07 04:12 PM
help me out with this - it's killing me.. popovsky[_8_] Excel Programming 6 July 22nd 05 09:20 AM
killing a sub from within an if statement Cliff L Excel Programming 8 May 11th 05 02:04 PM


All times are GMT +1. The time now is 09:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"