A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Pls share the sample to clear all your issues!!!
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We are trying to create a macro in Excel that will allow us to save an Excel Workbook, with multiple worksheets, without the formulas. When we try to run this macro, we get a Run-time error '13' Type mismatch message. The line that is in bold in the code below is where the debugger stops the run. Please help.
Sub NewWB()
Dim wbNew As Workbook
Dim wbThis As Workbook
Set wbThis = ThisWorkbook
Set wbNew = Workbooks.Add(xlWBATWorksheet)
wbThis.Worksheets("Crittenden").Range("A1:H1").CurrentRegion.Copy
With wbNew
.Worksheets(1).Range("A1:H1").PasteSpecial xlPasteValues
.Worksheets(1).Range("A1:H1").PasteSpecial xlPasteFormats
.SaveAs "C:" & wbThis.Worksheets("Crittenden").Range("A1:H1")
.Close True
End With
Set wbThis = ThisWorkbook
Set wbNew = Workbooks.Add(xlWBATWorksheet)
wbThis.Worksheets("Cross").Range("A1:H1").CurrentRegion.Copy
With wbNew
.Worksheets(1).Range("A1:H1").PasteSpecial xlPasteValues
.Worksheets(1).Range("A1:H1").PasteSpecial xlPasteFormats
.SaveAs "C:" & wbThis.Worksheets("Cross").Range("A1:H1")
.Close True
End With
End Sub
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Pls share the sample to clear all your issues!!!
We've got the syntax on the line that saves the file correct, but now it just overrides the file after each "End With". I need "Crittenden" and "Cross" to be separate tabs (worksheets) in the workbook "District3". All I'm getting now is a workbook that says District3, but with one worksheet named "Sheet1". It reads "Crittenden", writes it, and then reads "Cross and overwrites "Crittenden". PLease help.
Sub District3()
Application.Goto Reference:="District3"
Dim wbNew As Workbook
Dim wbThis As Workbook
Set wbThis = ThisWorkbook
Set wbNew = Workbooks.Add(xlWBATWorksheet)
wbThis.Worksheets("Crittenden").Range("H2").CurrentRegion.Copy
With wbNew
.Worksheets(1).Range("A1").PasteSpecial xlPasteValues
.Worksheets(1).Range("A1").PasteSpecial xlPasteFormats
.SaveAs "C:" & ("District3.xlsx")
.Close True
End With
Set wbThis = ThisWorkbook
Set wbNew = Workbooks.Add(xlWBATWorksheet)
wbThis.Worksheets("Cross").Range("H2").CurrentRegion.Copy
With wbNew
.Worksheets(1).Range("A1").PasteSpecial xlPasteValues
.Worksheets(1).Range("A1").PasteSpecial xlPasteFormats
.SaveAs "C:" & ("District3.xlsx")
.Close True
End With
I get a compiler error when I do the following:
.SaveAs wbThis.Path& "C:\District3.xlsx"
Wrong syntax?
Hi,
In addition to Jan Karel Pieterse reply if you wish to save new workbook in same directory then use this
.SaveAs wbThis.Path&"ABCD.xlsx"
or Explain more/share a sample.
Range("A1:H1") is a set of 8 cells so the macro tries to pass an array of 8 values to a string concatenation. This is not allowed. In other words:
You cannot use the value of more than one cell if you want to join together multiple strings. What is the cell containing the filename you need?
What is in A1:H1?