Compile Error Expected End With Excel
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies excel compile error expected = of this site About Us Learn more about Stack Overflow the company excel vba compile error expected = Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges excel vba compile error expected array Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a excel vba compile error expected expression minute: Sign up VBA Error: “Compile error: Expected End Sub” up vote 1 down vote favorite Trying to pass "GetFullNamePDF()" to the Filename attribute, but getting the following error: "Compile error: Expected End Sub" Sub PrintPDF() Function GetFullNamePDF() As String GetFullNameCSV = Replace(ThisWorkbook.FullName, ".xlsm", ".pdf") End Function ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "GetFullNamePDF()", Quality:=xlQualityStandard, IncludeDocProperties _ :=True, IgnorePrintAreas:=False, OpenAfterPublish:=False End Sub I know
Excel Vba Compile Error Expected Identifier
nothing about VBA, and got the above code from a question I asked yesterday, but was unable to test at the time. Guessing the error has to do with the function, since the code works without the function added and the filepath/name hard coded. Idea of the code is to dynamically use the filename of itself to name the path and file for the PDF. If you have any questions, just comment -- thanks! excel vba share|improve this question asked Dec 17 '10 at 15:40 blunders 1,58272759 add a comment| 3 Answers 3 active oldest votes up vote 3 down vote accepted You can't nest a function inside a procedure. You need to move it above: Function GetFullNamePDF() As String GetFullNameCSV = Replace(ThisWorkbook.FullName, ".xlsm", ".pdf") 'This should be GetFullNamePDF = Replace(ThisWorkbook.FullName, ".xlsm", ".pdf") End Function Sub PrintPDF() 'Remove the quotes from GetFullNamePDF ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ GetFullNamePDF(), Quality:=xlQualityStandard, IncludeDocProperties _ :=True, IgnorePrintAreas:=False, OpenAfterPublish:=False End Sub share|improve this answer answered Dec 17 '10 at 15:44 kgiannakakis 76k16124166 Thanks for taking the time to read the code and make sure everything is right;
Forum Microsoft Office Application Help - Excel Help forum Excel Programming / VBA / Macros vb error compile error Expected End with To get replies by our experts at nominal charges, follow this link to buy points
Compile Error Expected End Of Statement
and post your thread in our Commercial Services forum! Here is the FAQ compile error expected end of statement macro for this forum. + Reply to Thread Results 1 to 5 of 5 vb error compile error Expected End with Thread compile error expected end of statement visual basic Tools Show Printable Version Subscribe to this Thread… Rate This Thread Current Rating Excellent Good Average Bad Terrible Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 11-28-2010,06:10 http://stackoverflow.com/questions/4472095/vba-error-compile-error-expected-end-sub PM #1 00Able View Profile View Forum Posts Forum Contributor Join Date 11-17-2010 Location Pittsburgh, PA MS-Off Ver Excel 2003, 2007, 2010 Posts 244 vb error compile error Expected End with So with a lot of help, I have added a calendar to a userform, however, now when I test the userform to make sure it works, I get an error that reads "COMPILE ERROR: EXPECTED END WITH" as soon http://www.excelforum.com/showthread.php?t=754768 as I hit Submit. I am not sure how to fix this, any suggestions would be appreciated? I would copy the code, but as I am not sure where the error is derived from I don't believe copy all the code would be beneficial. Last edited by 00Able; 11-28-2010 at 07:07 PM. Register To Reply 11-28-2010,06:43 PM #2 davesexcel View Profile View Forum Posts Visit Homepage Forum Guru Join Date 02-19-2006 Location Regina MS-Off Ver XL 2010,2016 Posts 9,372 Re: vb error compile error Expected End with Please Login or Register to view this content. where is the End with? , Excel MVP Xlorate.com, Selection Codes, YouYube Channel Register To Reply 11-28-2010,06:43 PM #3 solnajeff View Profile View Forum Posts Forum Contributor Join Date 04-21-2007 Location Lima, Peru MS-Off Ver 2000, 2007, 2010 Posts 674 Re: vb error compile error Expected End with Hi You need to complete any With statement with and End With statement after your last line of relevant code. Regards Jeff Register To Reply 11-28-2010,06:44 PM #4 Richard Buttrey View Profile View Forum Posts Forum Moderator Join Date 01-14-2008 Location Stockton Heath, Cheshire, UK MS-Off Ver Excel for Windows & Mac - all versions. Posts 19,335 Re: vb error comp
soon) Ruby (coming soon) Getting Started Code Samples Resources Patterns and Practices App Registration Tool Events Podcasts Training API Sandbox Videos Documentation Office Add-ins Office Add-in https://msdn.microsoft.com/en-us/library/office/gg264694.aspx Availability Office Add-ins Changelog Microsoft Graph API Office 365 Connectors Office 365 https://bytes.com/topic/visual-basic/answers/907558-how-fix-compile-error-expected-end-sub-vba-macro REST APIs SharePoint Add-ins Office UI Fabric Submit to the Office Store All Documentation https://www.yammer.com/ http://feeds.feedburner.com/office/fmNx Office VBA language reference Visual Basic language reference Error Messages Error Messages Expected End Sub Expected End Sub Expected End Sub #Else clause must be preceded by a matching #If #Else compile error If, #Else, or #End If must be preceded by a matching #If #ElseIf must be preceded by a matching #If or #ElseIf and followed by an #ElseIf, #Else, or #End If
+ Ask a Question Need help? Post your question and get tips & solutions from a community of 418,469 IT Pros & Developers. It's quick & easy. How to fix "Compile error: Expected End Sub" in VBA Macro? P: 1 Dorota Prywata Hi, I need help with VBA Macro for Auto-filter to high lite a header plp advice as per below course a I got Compile error: Expected End Sub ? Expand|Select|Wrap|Line Numbers SubMacro1() FunctionFilterOn(myCellAsRange)AsBoolean OnErrorResumeNext WithmyCell.Parent.AutoFilter With.Filters(myCell.Column-.Range.Column+1) If.OnThenFilterOn=True EndWith EndWith EndFunction EndSub Thanks, D Feb 3 '11 #1 Post Reply Share this Question 1 Reply Expert Mod 2.5K+ P: 2,543 Stewart Ross You can't define a function (lines 3-10) WITHIN the definition of a SUB (lines 1 and 12). You can CALL the function from the sub, but they must be separately defined. -Stewart Feb 3 '11 #2 reply Message Cancel Changes Post your reply Join Now >> Sign in to post your reply or Sign up for a free account. Similar topics How to fix "Compile Error Expected: end of statement" in a query? How to fix error when executing macro: "Compile Error Variable not defined"? Delete Record Button and Getting a "compile error" Right turns to RIGHT and I get "Compile Error -Expected Array "on error resume next" does not work! "instantiated from here" compile error when using template "Use of possibly unassigned field" compile error What would cause"Compile error in hidden module" docmd.RunSQL Update records in table how can I get rid of the "You are about to update" message Browse more Visual Basic 4 / 5 / 6 Questions on Bytes Question stats viewed: 8200 replies: 1 date asked: Feb 3 '11 Follow this discussion BYTES.COM © 2016 Formerly "TheScripts.com" from 2005-2008 About Bytes | Advertise on Bytes | Contact Us Sitemap | Visual Basic 4 / 5 / 6 Answers Sitemap | Visual Basic 4 / 5 / 6 Insights Sitemap Follow us to get the Latest Bytes Updates