Problem with ExportAsFixedFormat with selected sheets

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:=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



0
mfgtcb (3)
10/12/2011 11:24:31 AM
excel 39879 articles. 2 followers. Follow

0 Replies
433 Views

Similar Articles

[PageSpeed] 53

Reply:

Similar Artilces:

My hide sheet option in excel is not working
My hide sheet option in Excel is not working. It is grayed out so I can not toggle nor use it to hide or unhide sheets. Security is at Medium - would appreciate any insight into how to fix this. Is the sheet protected? You cannot hide a protected sheet. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "arleen" <arleen @discussions.microsoft.com> wrote in message news:D028B90F-6DDB-4DE6-9F5C-22C137FBE927@microsoft.com... > My hide sheet option in Excel is not working. It is grayed out > so I can not > toggle n...

Problems saving a worksheet with Links
Does anyone know how I can resolve this issue ... I have a directory which contains 129 worksheets which have links to external data (in a Master Spreadsheet) -- I need to copy these files into a New Directory, but kee the Master Spreadsheet (which they are linked to) in the original location. If I do a simple Cut & Past, the Reference Link to the Master Spreadsheet gets moved to the New Directory (where the file does not exist), but if I open the worksheet (in the original directory/location) and Save As to the New Directory, the worksheet saved in the New Directory maintains its link t...

RPC over HTTP problem #3
Hi, All! My network configuration: DC1, DC2 and MX (MS Exchange 2003, sp1). All of them Windows Server 2003. What was done: In the registry on dc1 and dc2 was created a new key: "NSPI Interface protocol sequences" with value: ncacn_http:6004. MX was promoted to be a GC. Installed RPC over HTTP windows component. MX was changed to be RPC-HTTP back-end server. On the MX Default Web Site was installed cerificate from the local authority running on DC2. On the RPC virtual directory anonymous access and integrated windows authentication were disabled. In the registry of MX the key HK...

How to create a ledger sheet
Hello. I have a database with the following tables:Customers, Orders, and PaymentsThe Customers table has a one-to-many relationship with the Orderstable. The Customers table also has a one-to-many relationship withthe Payments table.I am trying to create what I think is commonly called a ledger sheet.This sheet simply shows the dollar amount of every order that anindividual customer has placed (debits) and every payment that thecustomer has made (credits). It also shows a running balance. Entriesare shown in chronilogical order.I am having trouble creating a report that would draw debits from...

Error- Project is used by another user -Please select another proj
Please see the subject line, when im trying to open a particular project. it gives me following error. I checked the current users, there are no users. Apart from me. There are some non PA users,i tried to remove them from activity. inspite of me removing them from activity, im geting the same error. Help !!! Ramakrishnan Hello Ram, There is a stranded user in PA000001 table. You need to clear this User/Project combination. Ajay "Ram" wrote: > Please see the subject line, when im trying to open a particular project. > it gives me following error. > > I che...

Send/Receive Problem
I am using Outlook 2002 on an XP platform. I cannot get Outlook to check for Email at regular intervals. I have the my Outlook set to Send and Receive all my accounts every 10 minutes but nothing happens. The only way I can receive Emails is by manually using the Send/Recv button or pressing F9. Can anyone offer any help. In case it is relevant I am using Norton Internet Security 2003. PWS Not sure it it Yor problem, but Outlook has some problems with Noroton Antivirus runing and chekking e-mails. As far as I know, Outlook may stop recieving e-mails from POP3 servers due to very le...

Excel problem #3
I am attaching an excel file where i have a problem In the file are 2 sheets, Main & second I want to get data from second sheet to the main sheet by a formula by which the amount in the total column will be posted in the second sheet falling under various dates. I have done for 6 sept 2003 by way of example I do not know any formula by which i can do this automatically Please help me Attachment filename: example.xls Download attachment: http://www.excelforum.com/attachment.php?postid=444742 --- Message posted from http://www.ExcelForum.com/ Hi one way: ...

Sync net folder problem
I am sharing my calendar to my workmate with net folder. My PC is Win XP and Office 2000 and my workmate's is Win 98 and also Office 2000. I always find that My calender can't be updated from my workmate when I return office after I've taken my notebook for a few days. Can't net folder sync. data offline? Thx. your attention. Ken So Net Folders uses e-mail messages to send updates between computers so naturally you would have to be connected to your e-mail to get any updates. When you leave the office and are not connected you won't get any updates but as soon as ...

Userform combobox matchrequired = True; error with no selection
I have a userform that includes a combobox which is optional for the user, but if they do use it, they have to select one of the three values provided (no creativity allowed). This works fine if the user ignores the field, or if they make a selection. They can even click the combobox 'arrow' to see the values and then click to another part of the form without making a selection. They can tab through controls including this one without any problem. All good. However, a user may enter the field (mouseclick) thinking they might want to make a selection, then decide again...

chart line style problem
I am making a scatter chart (with lines) in Excel 2007 under Vista. I can select a line style, for example, long dashes. However, if I try to change the axis (change from "automatic" to "fixed" on the horizontal axis), the line on the chart immediately becomes solid again. The legend still shows the proper dashing. I can get the dashing partly back by making the line thinner, but only where the variation is fastest - regions where the derivative is near zero are still solid even for thin lines. I'll appreciate any help! frank I was not able to reproduce this. Can you...

auto forward problems
I setup a 'contact' for 5 existing users in Exchange 5.5 Administrator. I give the contacts the desired SMTP address where they want their mail forwarded to. I set the corresponding 'contact' as the 'alternate recipient' for each of the 5 as detailed in Q255697. 2 of 5 work, the other 3 do not. When sending to each of the 5, 3 return undeliverable stating "A configuration error in the e-mail system caused the message to bounce between two servers or to be forwarded between two recipients." Any ideas? -adam Adam SK wrote: > I setup a 'con...

Exchange 2003 with SP2 problems...
I installed the SP2 for exchange 2003 server tonight, and I'm getting some problems. I added the registry key to increase the DB size to 30GB per the instructions, but I don't get a confirmation in eventid 1216 as it says I should. In fact, the message in eventid 1216 looks mised up. See insert: The Exchange store '16384' is limited to First Storage Group\Mailbox Store (ATL-SBS) GB. The current physical size of this database (the ..edb file and the .stm file) is %3 GB. If the physical size of this database minus its logical free space exceeds the limit of First Storage Gro...

Active Directory/Exchange problem
All, Before I joined my current employer the admin here upgraded from Exchange 5.5 to Exchange 2000(Box A) and then added another Exchange 2000 box to the organisation(Box B)and migrated the data in Box A to Box B. Box B is now the working exchange server and Box A is no longer used. The problem is that if I actually shut down Box A I can add a new user to Active Directory but I am unable to modify a users email/smtp details. All mail can still be transferred with no problems which would lead me to believe that Exchange is Ok but there is some sort of Active Directory link between the two bo...

small problem
hi every body; i wrote a program that it has error ;plz help me :( using System; namespace ConsoleApplication45 { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("***********"); for (int i = 0; i < 1008; i++) { Console.BackgroundColor = ConsoleColor.DarkCyan; Console.Write(" "); } move(); // ***********error is for here***********************************************...

save as version 2003 problem
I'm working in vba in Access to create and save an Excel file. All's good except that one of the workstations this is runnign on is using Office 2007. I'm developing in 2003 and all the other workstatiosn they have are using 2003. It's very important that the files be saved in 2003 format. When I do this, it runs fine and saves as 97/95 objExcelBk.SaveAs sTempPath & sExcelFileName, xlExcel9795 ','56 = xl 2000/2003 I read online in a forum post that "56" is the correct code for saving as 2003 but that's when the code is written in 20...

Font problem with Office 2004 for mac
I have Tiger, whenever I try to Launch any Office program, as the the menu loads to 'optimizing font menu performance' It pops up with 'The font " " has been corrupted and should be removed'. It does this with MANY fonts, many of which I don't even have in my font folder. It does this every time during the program start, and most times even if I go through clicking ok 40-60 times it will sometimes freeze up anyway. Anyway to fix, get around this problem? Please email me at madefornothing@yahoo.com. Hi, this problem affects quite a few users, and there'...

form and query problem. please help.
All tables are linked with weak entities. However, when i enter data on the form I can't get it to let me enter more than one partipicant without access generating a new invoice id. however i need one invoice to many participants. It wont work and i have no idea what to do at this point. in addition the workshop will not let me add workshop to invoice. this is a small mdb and i'd like to email it to anyone who can assist me with the relationships as I think this is the problem but I don't know what to do. please help me. INVOICE invoiceNO - autonumber invoice prices WORKSHOP wo...

hide/change color of selected row headings
Is it possible to hide the row heading numbers for selected rows (i.e. rows 51 and greater) for just the selected sheet? I'd like to have a color with no row heading number appear that matches the fill color I select for the adjacent cells. Secondly, any ideas as to how I can prevent the user from scolling further down than a certain point (i.e. row 51). Thanks in advance. Joe Row headings are either on or off, you can't hide some. However, you can achieve a similar effect by hiding *all* headings (Tools/Options/General) and putting the numbers 1:51 in A1:A51. to limit scro...

Macro to apply alternate grey/white shading to selected paragraphs
Dear Experts: I would like to do paragraph shading using grey shading alternately. Example: this is a sample text This is another sample text This is yet another sample text This may be the last paragraph acquiring grey shading This is the penultimate paragraph This is the last paragraph With these 6 paragraphs selected, I would like to run a macro which applies grey shading alternately to the selected paragraphs, i.e. grey/ white (no shading) alternately. Help is much appreciated. Thank you very much in advance. Regards, Andreas Use Dim oRng As Range For i = 2 T...

Attendence sheet
Does anybody has Attendence excel file which i can use for tracking attendence. Nitin, see if one of these will work for you http://office.microsoft.com/en-us/results.aspx?Scope=TC&Query=Attendence -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "Nitin Kamurlekar" <knitin@lucent.com> wrote in message news:OBTmCZ28GHA.1492@TK2MSFTNGP02.phx.gbl... > Does anybody has Attendence excel file which i can use for t...

Hidden log on problem
On our XP Home laptop I have 2 users on the welcome screen, while my admin account uses (ctrl alt del) x2. All is fine until it goes into standby when I am in admin. Then on wake up the welcome screen comes back, but (ctrl alt del) x2 does nothing. I can't see a way to get back into my account without rebooting. Is there another way (opening one of the other accounts is as slow as rebooting)? Cheers, S On Mar 30, 9:26=A0am, "spamlet" <spam.mores...@invalid.invalid> wrote: > On our XP Home laptop I have 2 users on the welcome screen, while my a...

formula to get sheet name
hi, can a formula retreive a worksheet name or does it need to be macro based? thanks, N.S. Hi Nigel, This formula that takes care of the possible situation whereby you have only one sheet in the workbook and its name is the same as the workbook's. Note: CELL("filename") will only work if the file has been saved at least once and if the file is opened in a different language system, the argument "filename" will need to be changed manually to the corresponding word (e.g. in Spanish "nombrearchivo"): =LOOKUP(REPT("z",255),SUBSTITUTE(MID(CE...

Can't insert rows
I am using Excel 2007 and have just loaded a spreadsheet created in a previous version which is running in Compatibility mode. When I try to insert a row I get an message "Cannot shift objects off sheet". How do I insert rows on this sheet? No problem with another workbook loaded at the same time which was created in 2007. See if this helps http://support.microsoft.com/default.aspx?kbid=211769 "Cannot shift objects off sheet" error message when you hide columns in Excel -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my...

How to select other random cells
I have a 2 part question. I want to have a 1 question survey randomly filled out by 200 people. Column A lists the 1 questions. Columun b has ABCDE listed in cells B6 to b10. I would like 200 samples in columns c, d, e, etc. How do I set this up so that they randomly Coose B6 to B 10. Second part. On another spreadsheet, I have a similar situation, but the user has 10 answers to select from and I want them to randomly select all that apply. How would I do this? Thanks! ...

select worksheet
There is probably a very easy answer to this question, but if you don't know you ask. I want a specific worksheet to open when I open the workbook. Is there specific code that needs to be written or can I do it in the worksheet properties? The help files seem to be vague on this issue. Thank you for any help. ...