Compile Error Expected End Sub Excel Vba
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 expected end sub visual basic of this site About Us Learn more about Stack Overflow the company
Excel Vba Compile Error Sub Or Function Not Defined
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges excel vba compile error expected = 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 minute:
Excel Vba Compile Error Expected Array
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 nothing vba compile error expected end of statement 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 75.9k16124166 Thanks for taking the time to read the code and make sure everything is right; wise
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
Excel Vba Compile Error Variable Not Defined
Add-in Availability Office Add-ins Changelog Microsoft Graph API Office 365 Connectors Office
Excel Vba Compile Error In Hidden Module
365 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 excel vba compile error object library invalid 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 http://stackoverflow.com/questions/4472095/vba-error-compile-error-expected-end-sub #Else 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
»excelcommentsWant to join? Log in or sign up in seconds.|Englishlimit my search to /r/exceluse the following search https://www.reddit.com/r/excel/comments/3g1phy/vba_macro_throwing_an_expected_end_sub_error_not/ parameters to narrow your results:subreddit:subredditfind submissions in "subreddit"author:usernamefind submissions by "username"site:example.comfind submissions from "example.com"url:textsearch for "text" in urlselftext:textsearch for "text" compile error in self post contentsself:yes (or self:no)include (or exclude) self postsnsfw:yes (or nsfw:no)include (or exclude) results marked as NSFWe.g. subreddit:aww site:imgur.com vba compile error dogsee the search faq for details.advanced search: by author, subreddit...this post was submitted on 06 Aug 20151 point (100% upvoted)shortlink: remember mereset passwordloginAsk an Excel Question!excelsubscribeunsubscribe50,882 readers~37 users here now all new Solved Unsolved Waiting Discussion Pro Tip Templates Add-in PLEASE FULLY READ THE SIDE-BAR BEFORE SUBMITTING A POST! Where to Learn Excel & Advice Megathread Submission Guidelines and Sharing