copy from a closed Workbook error

KlausW

Active Member
Joined
Sep 9, 2020
Messages
445
Office Version
  1. 2016
Platform
  1. Windows
Hi every one

I'm trying to use this VBA code I found here in the Forum. To copy from a closed Workbook.

But it gets this error message "Object doesn't support this property or method (Error 438)", it could be because the data I want to copy from a closed Workbook has formulas in it. If that's the case, then there are some can help solve the challenge.

Any help will be appreciated

Best Regards

Klaus W

VBA Code:
Sub SkibsNr_Rektangelafrundedehjørner1_Klik()

' Defines variables

Dim wb1 As Workbook, wb2 As Workbook



' Disable screen updating to reduce screen flicker

Application.ScreenUpdating = False



' Define which workbook is which

Set wb1 = ThisWorkbook

Set wb2 = Workbooks.Open("D:\DNBR 2024\Ankomstseddel\Ankomst sedler fastbesætning og VPL\Adresse fastbesætning og VPL.xlsm")



' Copy range A1:W70 from the Data sheet of wb2

wb2.Sheets("SkibsNr").Range("B2:J61").Copy

' Paste the copied data to range A1 of the Data sheet in wb1

wb1.Sheets("SkibsNr").Range("b2").Paste



' Close wb2

wb2.Close



End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
What happens if you change
VBA Code:
wb2.Sheets("SkibsNr").Range("B2:J61").Copy

' Paste the copied data to range A1 of the Data sheet in wb1

wb1.Sheets("SkibsNr").Range("b2").Paste

to

VBA Code:
wb2.Sheets("SkibsNr").Range("B2:J61").Copy wb1.Sheets("SkibsNr").Range("B2")
 
Upvote 0
What happens if you change
VBA Code:
wb2.Sheets("SkibsNr").Range("B2:J61").Copy

' Paste the copied data to range A1 of the Data sheet in wb1

wb1.Sheets("SkibsNr").Range("b2").Paste

to

VBA Code:
wb2.Sheets("SkibsNr").Range("B2:J61").Copy wb1.Sheets("SkibsNr").Range("B2")
Hi MARK 858 it worked, it asks if I want to save the closed workbook, but I can't remember how to get Excel to skip it so it just closes by itself. Can it copy so its only Value not formula? Klaus W
 
Upvote 0
Hi MARK 858 it worked
You're welcome

it asks if I want to save the closed workbook, but I can't remember how to get Excel to skip it
Rich (BB code):
Application.DisplayAlerts = False
wb2.Close False
Application.DisplayAlerts = True

Although the DisplayAlerts part is probably overkill
 
Upvote 0
Can it copy so its only Value not formula?

Yes:

VBA Code:
wb2.Sheets("SkibsNr").Range("B2:J61").Copy
' Paste the copied data to range A1 of the Data sheet in wb1
wb1.Sheets("SkibsNr").Range("b2").PasteSpecial xlPasteValues
 
Upvote 0
Solution
Yes:

VBA Code:
wb2.Sheets("SkibsNr").Range("B2:J61").Copy
' Paste the copied data to range A1 of the Data sheet in wb1
wb1.Sheets("SkibsNr").Range("b2").PasteSpecial xlPasteValues
Hi everyone, thank you very much for your help. Just as it should be. Good day. Best Regards Klaus W
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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