Connect Form Control Button with Public Function

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
I need to understand how to connect a form control button to a public function. I am attempting to create a button for users to 'save as' an exe file that can only be opened by a specific application.

I am still learning VBA and trying to use a public function for the first time. I have spent some time going through posts and trying to put the pieces together but just still don't understand how to make it work.

VBA Code:
Public Function SaveSecureWorkbookToFile(Filename As String)

Dim XLSPadlock As Object

On Error GoTo Err

Set XLSPadlock = Application.COMAddIns("GXLS.GXLSPLock").Object

SaveSecureWorkbookToFile = XLSPadlock.SaveWorkbook(Filename)
Exit Function

Err:

SaveSecureWorkbookToFile = ""

End Function


Any help or suggestions are very welcome.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Application.COMAddIns is the collection of add-ins. Why would you be trying to save that or any of its members as a file?
 
Upvote 0
Application.COMAddIns is the collection of add-ins. Why would you be trying to save that or any of its members as a file?
Because the add in "GXLS.GXLSPLock" creates an exe application that saves files as XLSCE and can only be opened using the application created by the add in

I had created this sub which saves files as XLSCE but it wasn't linked to add in so didn't work.

VBA Code:
Sub CommandButton1_Click()
Dim fName As Variant
fName = Application.GetSaveAsFilename(, fileFilter:="Excel Files (*.xlsce), *.xlsce", Title:="Save As")
If fName = False Then Exit Sub
ActiveWorkbook.SaveAs Filename:=fName
End Sub
 
Upvote 0
Sorry, no idea what to do to accomplish what you're trying to do.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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