Activating workbook without macro function enabled Error 400.

GerrardSVK

New Member
Joined
Sep 18, 2023
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Pleas how can I write code for activating already opened workbook but not saved as macro supported format. When I try to write this simple code it doesnt work

Sub Makro4()
Workbooks(2).Sheets(1).Activate
Range("F6:F7").Select
Selection.Copy
End Sub

Is there any option to work with it? I just need to select som cells and copy them.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Your macro doesn't care if the other workbook is macro-enabled. Which line of code causes the error? I don't see anything here that would cause a 400. The only error I see is if no other workbook is open so there no Workbooks(2) but I think that would give a subscript error.

It is also safer to index a workbook using its name rather than a number. And you don't have to do all that Selecting. This will do the same thing without having to Activate or Select anything.

What do you want to do with the range you just copied?

VBA Code:
Sub Makro4()
   Workbooks(2).Sheets(1).Range("F6:F7").Copy
End Sub
 
Upvote 0
Hi,
I need to index workbook by number cause I will need to press button that will run this macro and I have a lot of exels that I will have opened but still need to do same with all of them so index by its name its not accepútable in my case I will have always one exel opened that will run this macro and then I will be opening other exels one by one and still need to do the same copy data from that range then paste it in primar exel then generate something than again copy data back.

Simply said I just need code that will aktivate workbook 2 independently of its name then copy data from exact range.

I suppose my code will work but no. Its so simple but still made error.
 
Upvote 0
Your macro doesn't care if the other workbook is macro-enabled. Which line of code causes the error? I don't see anything here that would cause a 400. The only error I see is if no other workbook is open so there no Workbooks(2) but I think that would give a subscript error.

It is also safer to index a workbook using its name rather than a number. And you don't have to do all that Selecting. This will do the same thing without having to Activate or Select anything.

What do you want to do with the range you just copied?

VBA Code:
Sub Makro4()
   Workbooks(2).Sheets(1).Range("F6:F7").Copy
End Sub
Hi that one that you wrote me is working but what is bad on my conception?
 
Upvote 0
I don't know, because there is still not enough information to diagnose why you got error 400.
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,262
Members
449,093
Latest member
Vincent Khandagale

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