Copy the excel sheet to another closed file

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hello, how can I copy an excel sheet to another locked file that is protected with a password of 555
And can I copy in format xlsx
But the important thing is to open the file automatically and copy without asking for a password



VBA Code:
Sub CopySheetToClosedWB()
Dim SourceSht As Worksheet
Dim ws As Worksheet
Set SourceSht = Sheets("sheet1")
Application.ScreenUpdating = False


Set closedBook = Workbooks.Open("C:\Users\Admin\Downloads\data.xlsm")


SourceSht.Copy After:=closedBook.Sheets("sheet2")

      
    
closedBook.Close SaveChanges:=True

Application.ScreenUpdating = True
End Sub
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
But the important thing is to open the file automatically and copy without asking for a password

In general:
VBA Code:
Set closedBook = Workbooks.Open(Filename:="C:\Users\Admin\Downloads\data.xlsm", Password:="555")
 
Upvote 0
Solution
In general:
VBA Code:
Set closedBook = Workbooks.Open(Filename:="C:\Users\Admin\Downloads\data.xlsm", Password:="555")
Thank you very very good. Can I replace the file path so that I can put the file anywhere on the device not just a disk C
 
Upvote 0
In theory, yes. So long as the destination folder exists, or you create it.
 
Upvote 0
In theory, yes. So long as the destination folder exists, or you create it.
Yes, how can I modify the code to open the file on more than one device when the two files exist, of course
 
Upvote 0
Yes, how can I modify the code to open the file on more than one device when the two files exist, of course

I'm not sure you can open two files with the same name at the same time. But as long as you do it one at a time you should be fine.
 
Upvote 0
I'm not sure you can open two files with the same name at the same time. But as long as you do it one at a time you should be fine.
It is not the same name, but after searching I succeeded in putting it in this way
VBA Code:
Sub Copysh()
Dim SourceSht As Worksheet
Set SourceSht = Sheets("sheet1")

Application.ScreenUpdating = False

  Set Closesh = Workbooks.Open(ThisWorkbook.Path & "\data.xlsm", Password:="555")
 
SourceSht.Copy After:=Closesh.Sheets(Closesh.Sheets.Count)

Closesh.Close SaveChanges:=True
Application.ScreenUpdating = True
End Sub

Thank you for your help
good night
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top