Calling Save

A

AMDRIT

Hello once again,

I am calling save via code as such

if not activeworkbook.saved then activeworkbook.save

in Workbook_BeforeSave, I make a string to be my filename as such

sFileName="C:\Saveme.xls"

Then I call the saveas routine as such

ActiveWorkbook.SaveAs Filename:=sFileName, addtomru:=True,
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False

And low and behold, nothing happens.

However, when I click the save button from the toolbar, everything works
fine. What is the difference? How can I perform the same save routine as
the button click?

Thanks.
 
A

AMDRIT

Ok, so I didn't know how to call the save directly from the toolbar so I
made this:

'Usage
dim x as CommadBarButton
set x = FindCommandButton("&Save")
if not x is nothing then x.execute

Function FindCommandButton(Caption As String) As CommandBarButton

Dim cmdbar As CommandBar
Dim cmdbtn As CommandBarButton
Dim cmdctl As CommandBarControl

For Each cmdbar In Application.CommandBars
For Each cmdctl In Application.CommandBars(cmdbar.Name).Controls
If cmdctl.Type = msoControlButton Then
Set cmdbtn = cmdctl

If cmdbtn.Caption = "&Save" Then
Set FindSave = cmdbtn
Exit Function
End If

End If
Next cmdctl
Next cmdbar

End Function

It seems to work pretty well
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top