简体   繁体   中英

Referencing workbook/sheet from another open workbook

I have an online report that when downloaded automatically opens as a *.csv file. I then open another Excel workbook containing various macros and want to copy the entire downloaded sheet (sheet1) over to the my main workbook either as a new sheet or into an existing blank sheet named "DATA".

My problem is referencing the open downloaded sheet as each time it is downloaded the name is different. My preference is to not save the downloaded workbook and then copy as I just delete the file when I am done.

Any help with referencing the downloaded file and activating it would be appreciated.

I've been thinking about Application.RecentFiles today and wonder if it would work here. The assumption is that the csv is the most recently opened file, ie, it's at the top of the Home>Recent list:

Sub ActivateMostRecentOpened()
Dim WbName As String

With Application
    WbName = Workbooks(.RecentFiles(1).Name, InStrRev(.RecentFiles(1).Name, .PathSeparator) + 1).Activate
End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM