MS ACCESS VBA CODE - open up an excel file, copy paste, save and copy file

santa12345

Board Regular
Joined
Dec 2, 2020
Messages
70
Office Version
  1. 365
Platform
  1. Windows
hello.
I am trying to do the following.

Within Access using VB to....

1. open up an excel file
2. copy and paste special (the exact same data to the exact same tab) ... just removing the formulas
3. save the file with the same name (skipping / don't want the excel prompts to display....etc..
4. close the file and copy to another location


Dim objExcelApp As Excel.Application
Dim wb As Excel.Workbook
Set objExcelApp = Excel.Application
Set wb = objExcelApp.Workbooks.Open("c:\ABC\123.xls")
objExcelApp.Visible = True

wb.Sheets("tab A").Select
wb.Sheets("tab A").Range("a1:aa2000").Copy
wb.Sheets("tab A").Range("A1:aa2000").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

wb.Sheets("tab B").Select
wb.Sheets("tab B").Range("a1:aa2000").Copy
wb.Sheets("tab B").Range("A1:aa2000").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

wb.Sheets("tab C").Select
wb.Sheets("tab C").Range("a1:aa2000").Copy
wb.Sheets("tab C").Range("A1:aa2000").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

wb.Application.DisplayAlerts = False

wb.Save

wb.Application.DisplayAlerts = True

wb.Close

Dim SourceFile, DestinationFile
SourceFile = "c:\ABC\123.xls"
DestinationFile = "c:\DEF\456.xls"
FileCopy SourceFile, DestinationFile ' Copy source to target.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi,
So what is your question? I've not tried your code as yet, but it seems to work as intended.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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