Open copy of excel workbook

Dear experts,

I am trying to open a new instance of an excel workbook i.e. i want to open a copy of an excel file change some data in that file, copy it, paste it in my workbook and then delete the copy of the file. Is this possible? i already made the part where i copy from a workbook and paste it in mine. But because i change some things that i don't want to save, i want to use a copy of the workbook.

thanks in advance:)
LVL 1
MarkVrenkenAsked:
Who is Participating?
 
Rory ArchibaldCommented:
You can't open it twice in the same instance of Excel, which is why you need a new instance. So for example:

Dim appXL as Excel.Application
Dim wbCopy as Excel.Workbook
set appXL = New excel.application
set wbcopy = appxl.workbooks.open(Filename:=activeworkbook.fullname, ReadOnly:=True)
' then add code to do what you need with the workbook copy
'...
wbcopy.close SaveChanges:=False
appxl.quit

Open in new window

0
 
Rory ArchibaldCommented:
You would need to use a template file, or open another instance of excel, open the file read-only, make changes and copy to the current instance.
0
 
MarkVrenkenAuthor Commented:
i won't be using a template file. Is this solution also possible if the workbook where i will copy from is already opened? i.e you can't open the file twice right?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
MarkVrenkenAuthor Commented:
Thanks, It works fine:)
0
 
MarkVrenkenAuthor Commented:
Hope i can ask a quick question again. How do i reference the copied workbook. I don't copy the active workbook but a other one and it doesn't fully work yet:(

thanks in advance!
0
 
Rory ArchibaldCommented:
change
Filename:=activeworkbook.fullname

Open in new window

to
Filename:=workbooks("someworkbook.xls").fullname

Open in new window

0
 
MarkVrenkenAuthor Commented:
What does this code actualy do because i need to do some operations and don't really understand if i open a copy of my file or just open the file...?

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.