+ Reply to Thread
Results 1 to 43 of 43

Compile error: Syntax error

  1. #1
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Compile error: Syntax error

    Sub Email()

    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim FileFullPath As String

    FileFullPath = ThisWorkbook.Path & "\" & Sheets("DataInput").Range("C13").Value & " " & "-" & " " & Sheets("DatInput").Range("C30).Value & ".pdf"


    Sheets("Master").ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:= _
    FileFullPath, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False


    Hi, the above is part of my codings for an excel sheet to be converted to pdf file, i have been getting errors such as Syntax error, Subscript out of range, on this part of the code, any idea what went wrong? when i took this part out,

    FileFullPath = ThisWorkbook.Path & "\" & Sheets("DataInput").Range("C13").Value & " " & "-" & " " & Sheets("DatInput").Range("C30).Value & ".pdf"


    Sheets("FixedPayer").ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:= _
    FileFullPath, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False


    It worked fine.


    Thank you!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Quote Originally Posted by tictacbean View Post
    when i took this part out,
    Which part you taken out?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Hi Sixthsense,

    I took out this part,

    FileFullPath = ThisWorkbook.Path & "\" & Sheets("DataInput").Range("C13").Value & " " & "-" & " " & Sheets("DatInput").Range("C30).Value & ".pdf"


    Sheets("FixedPayer").ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:= _
    FileFullPath, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False


    After I took out this part of the code, there was no error, so I guessed this part is the error?

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    That is the part performing the PDF conversion. If you took out that code then nothing will be done by the macro code since rest are just declarations of variables.

  5. #5
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Yeap, as in when I leave the code there, my other codes worked fine, as in codes which are not shown here. So I am just wondering what is wrong with this part of my codes? Do you have any idea?

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Replace this line

    Please Login or Register  to view this content.
    With

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Hi Sixthsense,

    I am still getting error after replacing the line, this time round is Run-time error '9': Subscript out of range.

    Thanks.

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    On which line?

  9. #9
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    The line you asked me to use to replace the old line

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Whether the sheet named DataInput do exist in your workbook?

  11. #11
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Yeap it does exist in my workbook

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Sheets("DatInput").Range("C30).Value
    Typo error in the second reference.

    It should be DataInput. a is missing in the sheet name. Correct it.

  13. #13
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Ya,I saw that and I corrected it, still having the same error. The following code was highlighted with the arrow pointing at the last line,

    Sheets("FixedPayer").ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:= _
    FileFullPath, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

  14. #14
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Check whether the sheet FixedPayer do exist in your workbook?

  15. #15
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Yeap it is.

  16. #16
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  17. #17
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Sorry, but how do i attach a sample workbook? Am still quite new in this. Haha

  18. #18
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  19. #19
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Compile error: Syntax error

    If you're getting a Subscript out of range error, the sheet is not called what you think it is.
    Remember what the dormouse said
    Feed your head

  20. #20
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Sixthsense >> oh you mean attach my file here? I need some time to tidy up

    Hi romperstomper >> Hmmm but my sheet is the exact same name, is there a way to verify that?

  21. #21
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Compile error: Syntax error

    Select that sheet, then run this code:
    Please Login or Register  to view this content.
    If you see the message True, then the sheet name is correct.

  22. #22
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Yeap, the message is True. Now I am also having this error, "Document not saved. The document may be open, or an error may have been encountered when saving." And "Run-time error '1004': Application-defined or object defined error"

  23. #23
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Anyone can help?

  24. #24
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Attach file or screenshot

  25. #25
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Here you go.

    screenshot.png

  26. #26
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Also post the screenshot of the FixedPayer sheet to check the sheet name.

  27. #27
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    This screenshot can?

    ss.png

  28. #28
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    What version of Ms-Office it is? Is it mac?

  29. #29
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Nope, this is Windows 7.

  30. #30
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Everything seems to be okay, could you please create a copy of that workbook and delete all the sheets except FixedPayer.

    Also delete all the data from FixedPayer sheet (Ctrl+A and delete) and attach the file here for our testing?

  31. #31
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Delete all data from the excel FixedPayer excel sheet is it? Leave the code alone? I have a button on the FixedPayer sheet to execute the code.

  32. #32
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    Yes, nothing is required.

    Just keep the FixedPayer and code that's enough for testing. Also let us know your actual Ms-Office version.

    Caution: Do all those things in the duplicate copy and attach it here.

  33. #33
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Okay done, I am using Microsoft Excel 2007.

    NDS.xls

  34. #34
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    I hope I fixed your issue.

    In 2007 the SaveAs pdf is not made available by default.

    Press F12 key and see whether SaveAs PDF type is available like the below screenshot.

    If it is not available then you have to download the exe file from microsoft site and run it. After that press F12 in your excel workbook and the SaveAs PDF type will get added in the list.

    https://www.microsoft.com/en-in/down...ails.aspx?id=7
    Attached Images Attached Images

  35. #35
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    I see it is available on my side.

    saveas.png

  36. #36
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Compile error: Syntax error

    The code in your workbook is running nicely in my end.

    Sorry I don't have any other suggestions to offer.

    I will call all members help for this thread.

  37. #37
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Ah, could it be any settings I have to make or something?

  38. #38
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Compile error: Syntax error

    What is the result of

    Please Login or Register  to view this content.



  39. #39
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Hi snb,

    I tried and the result is false. Any idea why?

  40. #40
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Compile error: Syntax error

    Sixth Sense said you are getting an error. What is the error and where?

    Also I note you have an "On error resume next" this is generally bad practice (I wanted to put: really, really dangerous) as it just hides problems and causes unpredictable results. I would get rid of it and put in specific handling for error scenarios.


    click on the * Add Reputation if this was useful or entertaining.

  41. #41
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Compile error: Syntax error

    Try running the code but replace the FileFullPath with
    Please Login or Register  to view this content.
    If this works, I suspect the input in C13 and C30 of DataInput either has some characters that can't be used as a file name or have some errors in it.

    If that fails, then take it one more step and try this
    Please Login or Register  to view this content.
    Last edited by quekbc; 02-05-2016 at 06:51 PM.

  42. #42
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Compile error: Syntax error

    Quote Originally Posted by tictacbean View Post
    Hi snb,

    I tried and the result is false. Any idea why?
    Just try to learn how to deconstruct code and how to test its components:

    Please Login or Register  to view this content.

  43. #43
    Registered User
    Join Date
    01-27-2016
    Location
    Singapore
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Compile error: Syntax error

    Hi quekbc, yes you are right! The inputs in the cell C13 and C30 had invalid symbols in the file name, I had "/" in my filename. I have since changed the name and managed to resolve it.

    Thanks a lot for your help and the rest who responded to my questions!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compile Error:Syntax Error
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2014, 03:52 PM
  2. Compile Error syntax error
    By ixelister in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2014, 03:17 PM
  3. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  4. [SOLVED] first timer using VB to cut and paste macro - getting compile error syntax error
    By jopedder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2013, 11:45 AM
  5. [SOLVED] Compile Error : Syntax Error
    By sagar007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2013, 08:29 AM
  6. [SOLVED] Compile Error: Expected Expression, Syntax Error
    By gjohn282 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 11:28 PM
  7. Compile error: Syntax error
    By ttik in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2011, 09:45 PM
  8. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1