Microsoft Visual Basic Compile Error Expected End Sub
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss compile error expected end with the workings and policies of this site About Us Learn more compile error expected end with vba about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow vba compile error expected end sub Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping private sub commandbutton1_click() compile error expected end sub 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() Function GetFullNamePDF() As String GetFullNameCSV = Replace(ThisWorkbook.FullName, ".xlsm", ".pdf") End Function ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=
Compile Error Block If Without End If
_ "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, ".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
" 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 the register link above to proceed. To start viewing messages,
Compile Error Expected End Of Statement
select the forum that you want to visit from the selection below. Results 1 to 11 of can't execute code in break mode 11 Thread: [RESOLVED] Visual basic'S error " Compile Error : Expected End Sub" and where it comes? Tweet Thread Tools Show Printable Version Subscribe to sub or function not defined 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 Thread Starter New Member Join Date Oct 2013 Posts 7 [RESOLVED] Visual basic'S error " Compile Error : http://stackoverflow.com/questions/4472095/vba-error-compile-error-expected-end-sub 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 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) http://www.vbforums.com/showthread.php?736775-RESOLVED-Visual-basic-S-error-quot-Compile-Error-Expected-End-Sub-quot-and-where-it-comes = 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,826 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 to do or what fx() is supposed to be... so I'm not sure where to start. -tg * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.* * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways
+ Ask a Question Need help? Post your question and get tips & solutions from a community https://bytes.com/topic/visual-basic/answers/907558-how-fix-compile-error-expected-end-sub-vba-macro of 418,591 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) compile error 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 compile error expected 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: 8312 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