Compile Error Expected End Sub 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 compile error expected end with vba of this site About Us Learn more about Stack Overflow the company
Compile Error Expected End Of Statement
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges compile error expected end of statement macro 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 compile error expected end of statement visual basic 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
Compile Error Expected End With
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; wis
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 Availability compile error block if without end if Office Add-ins Changelog Microsoft Graph API Office 365 Connectors Office 365 REST APIs can't execute code in break mode 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
Sub Vba
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 If, #Else, or #End http://stackoverflow.com/questions/4472095/vba-error-compile-error-expected-end-sub 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
" Compile Error : Expected End Sub" and where it comes? If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click http://www.vbforums.com/showthread.php?736775-RESOLVED-Visual-basic-S-error-quot-Compile-Error-Expected-End-Sub-quot-and-where-it-comes the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 11 of 11 Thread: [RESOLVED] Visual basic'S error " Compile Error : Expected http://www.excelforum.com/excel-programming-vba-macros/722264-compile-error-expected-end-sub.html End Sub" and where it comes? Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Oct 2nd, 2013,07:52 AM #1 ilke View Profile View Forum Posts compile error Thread Starter New Member Join Date Oct 2013 Posts 7 [RESOLVED] Visual basic'S error " Compile Error : Expected End Sub" and where it comes? Please can someone tell me where i am making mistake? Visual basic is giving error , it is sayin " Compile Error : Expected End Sub " I am new with this program. I searched on the internet. I am using Private Sub or function wrongly i think. I put compile error expected end but it still saying "End Sub". Codes: Private Sub Form_Load() Dim i As Integer Dim x(1 To 100) As Double ir = 0 x(1) = 2: x(2) = 3: AERROR = 0.001 Public Function f(ByVal x As Double) As Double fx(i - 2) = x(i - 2) ^ 2 fx(i - 1) = x(i - 1) ^ 2 End Function End Sub Public Sub Calculate_Click() For i = 3 To 100 x(i) = x(i - 1) - ((fx(i - 1) * (x(i - 1) - x(i - 2))) / (fx(i - 1) - fx(i - 2))) If Abs(x(i) - x(i - 1)) < AERROR Then GoTo Solution ir = ir + 1 Next i Solution Print Sonuç = x(i), ir End Sub Reply With Quote Oct 2nd, 2013,08:15 AM #2 techgnome View Profile View Forum Posts PowerPoster Join Date May 2002 Posts 29,763 Re: Visual basic'S error " Compile Error : Expected End Sub" and where it comes? you're trying to put a function inside of a sub... you can't do that... also, your function as it is, doesn't return anything... further complicating it, your function uses a variable array fx that's undefined... the short of it, there's a lot more than just a "missing" end sub here... I'd try to fix it, but I don't know what it's doing, what it's supposed
Forum Microsoft Office Application Help - Excel Help forum Excel Programming / VBA / Macros Compile error: Expected End Sub To get replies by our experts at nominal charges, follow this link to buy points and post your thread in our Commercial Services forum! Here is the FAQ for this forum. + Reply to Thread Results 1 to 8 of 8 Compile error: Expected End Sub Thread 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 03-18-2010,12:40 PM #1 Leeboy View Profile View Forum Posts Registered User Join Date 03-18-2010 Location denmark MS-Off Ver Excel 2007 Posts 11 Compile error: Expected End Sub Hi I'm currently working on a small system where Excel has some rows to calculate. I wont explain in details what is should do, but when i run my VBA is says the error in the title of my thread. How my code looks: Please Login or Register to view this content. And. Is it possible to put more codes in one macro? Like as you see A14:I14 should be 227, and so. Can i put more of the same stuff in, so A15:I15 should be 225. So i only has to enable 1 macro at the time. Last edited by Leeboy; 03-18-2010 at 12:44 PM. Register To Reply 03-18-2010,01:06 PM #2 JBeaucaire View Profile View Forum Posts Visit Homepage @dministrator Join Date 03-21-2004 Location Bakersfield, CA MS-Off Ver 2010 Posts 31,611 Re: Compile error: Expected End Sub If this is a macro that is supposed to activate itself, then remove the first line of code, it's redundant. the ws_change line should be first. Also, this macro goes in the Sheet module itself, not a regular module (Module1 or Module2, etc.) _________________ Microsoft MVP 2010 - Excel Visit: Jerry Beaucaire's Excel Files & Macros If you've been given good help, use the icon below to give reputation feedback, it is appreciated. Always put your code between code tags. [CODE] your code here [/CODE] “None of us is as good as all of us” - Ray Kroc “Actually, I *am* a rocket scientist.”