Excel Macro Compile Error Expected End Sub
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions excel macro compile error expected end of statement you might have Meta Discuss the workings and policies of this compile error expected end sub excel vba site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers excel macro compile error sub or function not defined or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Excel Macro Compile Error Method Or Data Member Not Found
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a 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() excel macro compile error syntax error 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 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,58772859 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, "
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 Office Add-ins Changelog Microsoft excel macro compile error procedure too large Graph API Office 365 Connectors Office 365 REST APIs SharePoint Add-ins Office
Excel Macro Compile Error Next Without For
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
Excel Macro Compile Error In Hidden Module
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 If must be preceded by a http://stackoverflow.com/questions/4472095/vba-error-compile-error-expected-end-sub matching #If #ElseIf must be preceded by a matching #If or #ElseIf and followed by an #ElseIf, #Else, or #End If
Post your question and get tips & solutions from a community of 418,548 IT Pros & Developers. It's quick & easy. Compile Error Expected End Sub P: 1 rocky102 I am a novice https://bytes.com/topic/visual-basic/answers/852466-compile-error-expected-end-sub old timer who enjoys fooling around with excel, I copied this macro from and old computer and wanted to use it one a new one I got. Its supposed to draw a line across a row when there is a change from one number to another. When I try to use it I get this error Compile Error Expected End Sub Help please. Thanks Don Sub Macro1() ' ' Macro1 Macro ' Macro recorded 8/27/2008 by ' compile error ' Keyboard Shortcut: Ctrl+m Sub Drawline() Dim vValue Do Until ActiveCell = Empty vValue = ActiveCell ActiveCell.Offset(1, 0).Activate If ActiveCell <> vValue Then Range(ActiveCell, ActiveCell.Offset(0, 35)).Select With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With End If Loop End Sub Nov 9 '08 #1 Post Reply Share this Question 2 Replies P: 58 ubentook Add an apostrophe ' in front of Sub Macro1() Nov 9 '08 #2 reply 100+ P: 283 jg007 looking excel macro compile at this you seem to have created a macro and then copied the old macro inside it but you have also copied the start of the sub. if you start a sub - Expand|Select|Wrap|Line Numbers SubExample_Macro you then need to end that sub - Expand|Select|Wrap|Line Numbers EndSub if you record the macro excell will generate a sub for you - 'macro1' in your code, this sub will have a start and end and you have confused excel by starting another sub within that one and not finishing it. if you add an apostrophe " ' " it comments that line out so if you add the apostrophe before the " sub macro1 " excel will then just use your sub and you will see the macro name will also change to 'drawline' Nov 9 '08 #3 reply Message Cancel Changes Post your reply Join Now >> Sign in to post your reply or Sign up for a free account. Similar topics Compile error. compile errors. pls help Doesn't Compile, Why? compile error: new : cannot specify initializer for arrays compile error Jython compile errors ... Why still can't compile (simple) Is this an invalid program? Doesn't compile on my system c++ compile error on linux 64 bit machine compile time optimization problem Browse more Visual Basic 4 / 5 / 6 Questions on Bytes Question s