2
votes

I entered the following code into Visual Basic.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("$D$10:$S$29")) Is Nothing Then
ActiveWindow.Zoom = 80
Else
ActiveWindow.Zoom = 100
End If
End Sub

It works well to zoom in when a certain range is selected, and to zoom out when anywhere else on the page is selected.

When I go to save the workbook, the following message comes up:

"The following features cannot be saved in macro-free works: - VB project To save a file with these features, click No, and then choose a macr-enabled file type in the File Type list. To continue saving as a macro-free workbook, click Yes."

When saving I have changed the "save as type" to "Excel Macro-Enabled Workbook". This saves the text in the editor, but when I re-open the file, the macro doesn't work.

I have also saved the file without the macro entered as an "Excel Macro-Enabled Workbook" and then copied the macro into the workbook, checked to see if the macro works (it does), then save the file, close and re-open.

The say outcome of the macro being saved but not working.

How can I save this workbook so that the macro is saved with it and works each time I open the file?

Thank you very much in advance for your help.

1

1 Answers

0
votes

@user2879835, After you saved the workbook as "Excel Macro-Enabled Workbook" and while opening the same does it asking any security warnings like "Macros have been disabled"?...and also Worksheet_Change occur when cells on the worksheet either changed by the user or by any link.