Copy data from one sheet to another (1 Viewer)

Kiron

New member
Local time
Today, 13:22
Joined
Jul 23, 2019
Messages
9
Hi Champs

I request a code to be written in access where on pressing a button it asks the user to select an excel file . It then copies a specific sheet from that file and pastes it to another excel workbook specific sheet.
Data can be text or charts or pics, basically whatever is in the selected file should be pasted to another workbook sheet. Code should be able to define sheetnames so i know whats getting colied form where to where.
I have done this in excel vba. But am having a challenge when the same is to be done via access using excel in the background.

Pls advise if this is possible and how.
Thanks heaps
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:22
Joined
Sep 21, 2011
Messages
14,238
Well I would have thought it would be pretty much the same except you would prefix each command with the name of the Excel object?

In fact, why not just run your macro in Excel from Access?

 
Last edited:

vba_php

Forum Troll
Local time
Today, 15:22
Joined
Oct 6, 2019
Messages
2,880
In fact, why not just run your macro in Excel from Access?
is that even possible? I've actually never tried that. Kiron, you should look up how to do this. But here are some things that will guide:

=> create an excel instance:
SQL:
Dim xl As Excel.Application
Set xl = New Excel.Application
=> set the windows file picker:
SQL:
dim fso as filedialog
set fso = Application.FileDialog(msoFileDialogFilePicker)
=> declare your sources and targets:
SQL:
dim varFile as variant
Dim wb_src As Excel.Workbook
Dim ws_src As Excel.Worksheet
dim wb_trgt as excel.workbook
dim ws_trgt as excel.worksheet
set your source book, source sheet, target book, and target sheet after picking a file from the fso:
SQL:
With fso
    If .Show Then
        .AllowMultiSelect = false
        .InitialFileName = "C:\"
        .Filters.Add "EXCEL Files", "*xlsx, *xls"
           varFile = .selecteditems(1)
              Set wb_src = xl.Workbooks.Open(cstr(varfile))
              Set ws_src = wb_src.Worksheets("source sheet name here")
              Set wb_trgt = xl.Workbooks.Open("path of target book here")
              Set ws_trgt = wb_trgt.Worksheets("path of target sheet here")
    end if
end with
now write code to do your copying, which you can easily get from running the macro recorder and learning from it.
 

Users who are viewing this thread

Top Bottom