+ Reply to Thread
Results 1 to 8 of 8

Workbooks.OpenText Error

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Workbooks.OpenText Error

    So I've attached a sample workbook as well as the sample file (except please change the extension of the .txt file to a .bdf for this purpose) with the userform....when I run it I get a "compile error: expected function or variable" at the OpenText. I'm not sure I understand, I thought I set it up the correct way in my code...

    Any help would be appreciated.
    Attached Files Attached Files
    Last edited by sperry2565; 09-24-2013 at 04:09 PM. Reason: Uploaded edited xlsm

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Workbooks.OpenText Error

    opentext doesn't return anything so you need to use
    Application.Workbooks.OpenText Filename:=strFileB, Origin:=437, StartRow:=1, _
                DataType:=1, TextQualifier:=xlNone, ConsecutiveDelimiter:=True, _
                Tab:=True, Semicolon:=False, Comma:=False, Space:=True, Other:=False, _
                FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), TrailingMinusNumbers:=True
    Set tsiB = Activeworkbook
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: Workbooks.OpenText Error

    That's kind of weird....is it because it's not a text file that I want to open?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Workbooks.OpenText Error

    no-the opentext method simply doesn't return a workbook object reference. it doesn't matter what kind of file you open with it

  5. #5
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: Workbooks.OpenText Error

    Well I asked because I copied that code practically ver batim from a macro I recorded and it worked. And it worked before in previous code for me while using a CreateScriptingObject. Thanks though.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Workbooks.OpenText Error

    Quote Originally Posted by sperry2565 View Post
    practically verbatim
    I reckon that's the key phrase ;-) a macro would never attempt to use a variable there

  7. #7
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: Workbooks.OpenText Error

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        ChDir "C:\Users\jk514d\Desktop"
        Workbooks.OpenText Filename:="C:\Users\jk514d\Desktop\temp1.bdf", Origin:= _
            437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
            ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
            Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
            , 1), Array(4, 1)), TrailingMinusNumbers:=True
    End Sub

    Just so we're clear, that was the marcro, the only thing I changed was the way it gets the path to the file....

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Workbooks.OpenText Error

    Quote Originally Posted by sperry2565 View Post
    the only thing I changed was the way it gets the path to the file....
    no-you tried to assign the result of Opentext to a variable, which doesn't work because there is no result. the macro does not try to do that-it's just
    workbooks.opentext...
    and not
    set tsiB = Workbooks.opentext(...)

+ 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. Workbooks.OpenText Fieldinfo
    By Peterppp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2007, 05:33 AM
  2. Workbooks.Opentext - oldskool '97
    By bradsalmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-09-2006, 10:50 AM
  3. [SOLVED] Workbooks.OpenText StartRow:=2 Not Skipping Row 1
    By John Saunders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2005, 07:05 AM
  4. [SOLVED] Workbooks.OpenText does not work on XP. HELP !!!
    By richmarin@earthlink.net in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-31-2005, 11:05 AM
  5. [SOLVED] How to open UTF-8 files with Workbooks.OpenText
    By Mete Kural in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-06-2005, 09:06 PM

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