[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

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:)
0
MarkVrenken
Asked:
MarkVrenken
  • 4
  • 3
1 Solution
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now