WorkSheet To WorkBook cant be saved error

bloodmilksky

Board Regular
Joined
Feb 3, 2016
Messages
202
Hi Guys,

I am using the below code to save a sheet as a workbook. my query is that when I do run it a notification comes up saying:

"parts of this workbook you are trying to save can not be saved macro free : VB Project"

I just wondered if there is a way of saving this as a macro free workbook

Many thanks

Jamie

Code:
Sub Copy_Save_Worksheet_As_Workbook()


    Dim wb As Workbook
    Dim myPath As String
    Dim myFilename As String
    Dim myFileExtension As String
    myPath = "D:\" 'you can change this
    myFileExtension = ".xlsx"
    myFilename = ThisWorkbook.Sheets("EDI template").Range("REFNUMBER").Value
    Set wb = Workbooks.Add
    ThisWorkbook.Sheets("EDI template").Copy Before:=wb.Sheets(1)
    ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
    wb.SaveAs myPath & myFilename & myFileExtension
    wb.Close False
    Msg = "Would You Like To Load Another Order ? " & Application.UserName
    Ans = MsgBox(Msg, vbYesNo)
    If Ans = vbNo Then
                Range("Description").Select
                Selection.ClearContents
                Range("PXINFOR").Select
                Selection.ClearContents
                Application.DisplayAlerts = False
                ThisWorkbook.Save
                Application.DisplayAlerts = True
                Application.Quit
                End If
    If Ans = vbYes Then
                Range("PXINFOR").Select
                Selection.ClearContents
                Range("Description").Select
                Selection.ClearContents
                Run "NextOrder"
    
                End If
                
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I just wondered if there is a way of saving this as a macro free workbook
One way would be to have your VBA code copy the sheet to a new, blank workbook and save that.
 
Upvote 0
Heres a snippet of the code I would use to do that.

Code:
Application.DisplayAlerts = False
Sheets("Sheet1").Copy
Set wb = ActiveWorkbook
Application.DisplayAlerts = True

This will create a new workbook with just Sheet1 in it and assign that workbook to the variable wb
 
Upvote 0
Display the code you are using now. Just to say its erroring is not sufficient. What is the error code? What are the value of the variables at the time of error?
 
Upvote 0
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule #13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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