PDA

View Full Version : Solved: Reverse code on a macro



Robotek
05-23-2008, 12:47 PM
Hi fellas,

I recently formatted my harddrive and have probably not installed VBA again, since I was unable to run macros on an Excel program I commonly use.

I figured, since I hardly ever do anything with macros myself, I'd just search around for a code that "activates" the macros in the program I mentioned earlier. Knowing practically nothing about macros, I ran the code in this article (vbaexpress.com/kb/getarticle.php?kb_id=379) believing it would fix my problem. This wasn't the case since all worksheets disappeared, or hid :dunno

Now I've understood that it's not possible to undo macros, so I'm kindly asking someone for a reverse code for this. Anyone, please? :help


Best wishes from a cold Finland

Simon Lloyd
05-23-2008, 01:08 PM
You must have at least one worksheet visible! it is this portion that hides the sheets:
Private Sub HideAllSheets()
'Hide all worksheets except the macro welcome page
Dim ws As Worksheet

Worksheets(WelcomePage).Visible = xlSheetVisible

For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVeryHidden
Next ws
Worksheets(WelcomePage).Activate
End Sub
change it to:

Private Sub HideAllSheets()
'Hide all worksheets except the macro welcome page
Dim ws As Worksheet

Worksheets(WelcomePage).Visible = xlSheetVisible

For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = WelcomePage Then ws.Visible = true
Next ws
Worksheets(WelcomePage).Activate
End Sub
if you can change this in the workbook you ran it in you should be fine!

Robotek
05-25-2008, 03:51 AM
Thanks Simon, It worked!

I read "this" and if the point means what I think it means, then no, this is the only place I've posted my question on. Can't see any reason for posting it on many places.

Then a last question. I want the action that I was trying to do running the code (vbaexpress.com/kb/getarticle.php?kb_id=379) at the first time. I.e.g. activate my macros.

So, as I press a macro that referres to another sheet in the workbook, I get this errorscreen: "Cannot run the macro "abc.xls'!def'. The macro may not be available in this workbook or all macros may be disabled." and then as I press "ok" I get error code 40040.

I changed on microsoft>add or remove features>VBA for apps from install on first use to run from my computer, but this made no difference on my macros. Neither can I find anything like "enable macros" in excel (2007). If it could be of any use, I've changed names on the sheets after the macros were made (so "def" is actually named "ghi").


Take care
Robotek

Simon Lloyd
05-25-2008, 04:32 AM
In xl2007 you have to purposely save a workbook as macro enabled! however i don't know too much about 2007 best you start a new thread with that in the thread title!

Aussiebear
06-09-2008, 01:11 AM
Hi Robotek, You can set your macro options in Excel 2007 by doing the following: Office Button/Excel Options/Trust Centre/Trust Centre Settings/Macro settings and select Disable all macros with notifications, then click OK.