+ Reply to Thread
Results 1 to 6 of 6

getting Error Expected ')' at Line - 20

  1. #1
    Registered User
    Join Date
    09-11-2015
    Location
    India
    MS-Off Ver
    2010
    Posts
    10

    getting Error Expected ')' at Line - 20

    I have vbscript which will read text file and send mail of content but after running it getting error ----- Expected ')' line - 20


    Sub CatchMe()

    Dim outobj, mailobj
    Dim strFileText
    Dim objFileToRead
    Set outobj = CreateObject("Outlook.Application")
    Set mailobj = outobj.CreateItem(0)
    strFileText = GetText("C:\Users\AH0667770\Desktop\New folder (2)\1.txt")
    With mailobj
    .To = "[email protected]"
    .Subject = "Testmail"
    .Body = strFileText
    .Display
    End With
    'Clear the memory
    Set outobj = Nothing
    Set mailobj = Nothing
    End Sub

    Function GetText(sFile As String) As String
    Dim nSourceFile As Integer, sText As String
    nSourceFile = FreeFile
    'Write the entire file to sText
    Open sFile For Input As #nSourceFile
    sText = Input$(LOF(1), 1)
    Close
    GetText = sText
    End Function

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,623

    Re: getting Error Expected ')' at Line - 20

    Your code works fine for me. Suggest you post a sample workbook with the code in it and a copy of the text file you are reading.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-11-2015
    Location
    India
    MS-Off Ver
    2010
    Posts
    10

    Re: getting Error Expected ')' at Line - 20

    Please Login or Register  to view this content.
    File - 1.txt

    1

    updated now showing error

    Expected end of the statement at line 24

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: getting Error Expected ')' at Line - 20

    post a sample workbook
    Stop taking the easy way out for yourself - spend a little time to help others who may help you.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,623

    Re: getting Error Expected ')' at Line - 20

    What can I say? If you just keep providing the same information, you're just going to get the same answer. It worked for me with a text file I have in my downloads folder.

    I can see the name of the file and its location in the code. If there is an error, I assume it relates to your file, because I don't get an error with mine.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: getting Error Expected ')' at Line - 20

    Hi,

    If you are running this as VBScript, it will not work. You cannot use Open and Close- you will have to use the Scripting.Filesystemobject instead. Also, you cannot declare variable types or function return types in VBScript.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ 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 expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  2. Specific line of my macro isnīt working as expected
    By Marceltcm in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-30-2013, 11:47 AM
  3. [SOLVED] Continue code on next line: Compile Error: expected list separator or )
    By ike609 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-05-2012, 08:28 AM
  4. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  5. GoTo compile error: "Expected: line number or label"
    By elfsprin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-29-2011, 09:21 PM
  6. 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
  7. OR Operator Line Not Giving Expected Result
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2010, 06:14 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