Results 1 to 2 of 2

Run Workbooks.OpenText from Word

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Run Workbooks.OpenText from Word

    I am creating documentation that we use to run daily tasks and I am trying to automate some of it. Part of the process we need to import a few text files into excel then save them after a few modifications into another folder. I coded it first in excel, now I am moving it into Word and this is the code I have:

    Dim xl As Excel.Application: Set xl = CreateObject("Excel.Application")
        Dim wbs As Excel.Workbooks
        Dim wb As Excel.Workbook
        
        xl.ScreenUpdating = False
        'DGSF001
        Set wb = Workbooks.OpenText(FileName:=cSalesForceDownloadLocation & sf1 & MMDDYYFormat & ".TXT", Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
            xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
            Array(2, 2), Array(3, 1), Array(4, 2), Array(5, 2), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 2), Array(10, 2), Array(11, 1), Array(12, 2), _
            Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 2), Array(22, 1), _
            Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), _
            Array(33, 1), Array(34, 1), Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array(41, 1), Array(42, 1), _
            Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array(47, 1), Array(48, 2), Array(49, 2)), TrailingMinusNumbers:=True)
        wb.SaveAs FileName:=cSalesforcePath & YYYYMMDDFormat & "\" & cAProducer & sf1 & MMDDYYFormat & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        wb.Close
    It looks correct but I keep receiving a compile error on the Worksbooks.OpenText line that says "Expected Function or Variable." That works in Excel. I even tried Excel.Workbooks.OpenText and xl.Workbooks.OpenText. I already set a Reference to the Excel Object model in the References section. What am I missing here?
    Last edited by djblois1; 05-13-2022 at 03:59 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Workbooks.OpenText parses out spaces?
    By Oppressed1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2019, 01:30 PM
  2. [SOLVED] Workbooks.OpenText Error
    By sperry2565 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-25-2013, 04:03 PM
  3. Workbooks.OpenText Fieldinfo
    By Peterppp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2007, 05:33 AM
  4. Workbooks.Opentext - oldskool '97
    By bradsalmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-09-2006, 10:50 AM
  5. Workbooks.OpenText problem in XL2000
    By Mike Iacovou in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-18-2006, 01:15 PM
  6. [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
  7. [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

Tags for this Thread

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