Remove text box before saving using macros

rp4717

New Member
Joined
May 29, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have an invoice that has macros. I am trying to find a way to delete or hide them when I am saving the Invoice in a folder. They are in the form of text boxes. This is the code for the macro I am using to save the invoice.
Sub SaveInvoice()
Dim invoiceNumber As String
Dim customerName As String
Dim fileName As String
Dim filePath As String

' Get the invoice number and customer name from specific cells
invoiceNumber = Range("F5").Value
customerName = Range("A9").Value

' Construct the file name and file path
fileName = "Invoice_" & invoiceNumber & "_" & customerName & ".xlsx"
filePath = "C:\Users\Dell\Desktop\Invoices\" & fileName

' Save the active workbook with the constructed file path
Application.DisplayAlerts = False ' To suppress overwrite confirmation dialog
ThisWorkbook.SaveAs fileName:=filePath, FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True ' Restore display alerts

' Display a message box with the saved file path
MsgBox "Invoice saved at: " & filePath
End Sub

Thanks for the help!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You didn't say if they are activex controls or not, so perhaps if you add this before you save
VBA Code:
Dim obj As OLEObject
For Each obj In ActiveSheet.OLEObjects
     If obj.progID = "Forms.TextBox.1" Then obj.Delete
Next
Make sure you test that on a copy of your workbook as there will be no way to undo. Might be safer to hide instead?
Please post code within code tags (vba button on posting toolbar) to maintain code indentation and readability.
 
Upvote 0

Forum statistics

Threads
1,215,151
Messages
6,123,316
Members
449,094
Latest member
Chestertim

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