Macro won't close fie after opening it

simongilder

Board Regular
Joined
Nov 3, 2011
Messages
68
Hi,

Please could you help with the code below, I am very new to VBA

I want to open a file whose filepath and name are determined in A1 of Sheet1. Then I want to copy the entire sheet "S1" from the newly opened workbook back to the original workbook, and paste values to a Sheet called "dump".

This seems to work fine, but I cannot get the source file to close afterwards.

Any help would be gratefully received.

Thank you.

Simon


Dim strFName As String

strFName = Sheet1.Range("A1").Value
Workbooks.Open Filename:=strFName


Worksheets("s1").Range("a1:AZ1000").Select
Selection.Copy
ThisWorkbook.Activate
ActiveWorkbook.Sheets("Dump").Activate
Range("A1").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This will close it withous saving:

Code:
Worksbooks(strFName).Colse False
Code:

This will close and save it:

Code:
Worksbooks(strFName).Close True
Code:
 
Upvote 0
Have you tried

Workbooks(strFName).Close SaveChanges:=False

Hi, thanks for the prompt reply.

I added that to the code but the macro debugged at the last line.

Could you help?

Thanks

Simon




Dim strFName As String

strFName = Sheet1.Range("A1").Value
Workbooks.Open Filename:=strFName


Worksheets("s1").Range("a1:AZ1000").Select
Selection.Copy

ThisWorkbook.Activate

ActiveWorkbook.Sheets("Dump").Activate

Range("A1").Activate

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


Workbooks(strFName).Close SaveChanges:=False
 
Upvote 0
The code you are posting appears to be incomplete, and cannot be annalyzed properly as is. The pasteSpecial statement does not have a copy statement shown and if missing in the full procedure, that would cause an error message to be gererated, if this is part of a valid macro.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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