Consulting

Results 1 to 2 of 2

Thread: copy data from .csv file to other excel files

  1. #1
    VBAX Newbie
    Joined
    Sep 2018
    Posts
    2
    Location

    Smile copy data from .csv file to other excel files

    Since I am new to VBA I created a code which can open a .csv file and copy data from .csv to an excel file without opening both.(It looks like both are not opening)

    My source file is a .csv (AAA.csv) and my destination file is a .xlsx (BBB.xlsx) which has various multiple sheets but I need to paste into sheet name "FEES"

    Actually it works for excel files but When I use a .csv file it displays me an error message "SUBSCRIPT OUT OF RANGE".How do I solve this? Thank You!


    Sub Copywb1()
    Dim wkb1 As Workbook
    Dim sht1 As Worksheet
    Dim wkb2 As Workbook
    Dim sht2 As Worksheet

    Application
    .ScreenUpdating =False
    Application
    .DisplayAlerts =False
    Application
    .EnableEvents =False

    Set wkb1
    = ThisWorkbook
    Set wkb2
    = Workbooks.Open("C:\Desktop\BBB.xlsx")
    Set wkb1
    = Workbooks.Open("C\Reports\AAA.csv")
    Set sht1
    = wkb1.Sheets("Reports")
    Set sht2
    = wkb2.Sheets("Fees")

    sht1
    .Range("A1:BM9").Copy
    sht2
    .Range("A1").PasteSpecial xlPasteValues
    Application
    .CutCopyMode =False
    wkb2
    .Close True
    wkb1
    .Close True

    EndSub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Just looking it, I think you forgot the colon in


    Set wkb=Workbooks.Open("C\Reports\AAA.csv")
    
    
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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