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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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