Help with error 400.

alfranco17

Board Regular
Joined
Apr 14, 2013
Messages
190
Hi.

I'll really appreciate any hints you can give me on this one.

I have the following code:

Code:
Sub PrepareFilesForReport()

    Dim v_expense As Workbook
    Dim v_template As Workbook
    
    ' Open template file.
    Set v_template = Workbooks.Add(Range("Template_Path"))
    
    ' Go back to the macro workbook so that the Range("expense_Path") is available
    ThisWorkbook.Activate
    
    ' Open expense file.
    Set v_expense = Workbooks.Open(Range("expense_Path"))
    
    ' Make sure the file we just opened is active.
    v_expense.Activate
    
    ' Move the only sheet that file has to the template.
    ActiveSheet.Move Before:=v_template.Sheets(1)
    
    ' Activate the template file (should be active already).
    v_template.Activate
    
    ' The following line produces error 400
    ActiveSheet.Name = "ExpenseSheet"
    
End Sub

It was working fine. Suddenly, there is a computer that shows the "Error 400" dialog box.

I tried to use:

Code:
v_template.ActiveSheet.Name = "ExpenseSheet"

It did not work either.

If I go to the immediate window, it shows me the activeworkbook is the right one, it gives me the name of the sheet, but as soon as I try to run the macro and change the name I get error 400.

If I test it in my computer, it works. I am running Excel 2016, in Enlish. The other computer is running Excel 2013, in Spanish. But it had not failed before.

Is there a way to make the code bullet-proof and avoid that error? Or any other solutions you may think of? I am in a loop right now.

Thanks.
Armando.
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,767
Members
413,933
Latest member
Msar5586

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
Top