Consulting

Results 1 to 3 of 3

Thread: Solved: Defining .csv-file as workbook

  1. #1

    Solved: Defining .csv-file as workbook

    I'm working with a .csv-file which I open like this:

    [vba]Workbooks.OpenText Filename:="C:\abc.csv", Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, Comma _ 'etc
    [/vba]

    How do I define the .csv-file as a workbook?

    [vba]Dim MyFile As Workbook
    MyFile = 'what do I put here?[/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub OpenCsv()
    Dim MyFile As Workbook
    Set MyFile = Workbooks.Open(Filename:="C:\abc.csv")
    MsgBox MyFile.Sheets.Count
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Since the .csv-file is already open, I used
    [VBA]Dim MyFile As WorkBook
    Set MyFile = Workbooks("abc.csv")[/VBA]
    And it worked fine.

Posting Permissions

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