Solved

VB works as module in worksheet but not in personal.xls

Posted on 2008-06-10
2
373 Views
Last Modified: 2013-12-26
I have pieced together this module from code I found here and around.  It is simple,  it walks through each worksheet in an excel project and removes all hyperlinks and images.  However when I went to create an add in with a toolbar so I could share it,  the code no longer works as it did before.  It only removes hyperlinks from the current sheet and it removes no images that I am aware of.
Sub CleanSheet()
Dim mysheet As Worksheet
Dim shp As Shape

Set mysheet = ActiveSheet
  'Step through each sheet in the workbook
  For Each mysheet In ThisWorkbook.Sheets
     'Step through and delete each shape in the current sheet
    For Each shp In mysheet.Shapes
        shp.Delete
    Next shp
  'Remove all hyperlinks from the active sheet.
  ActiveSheet.Hyperlinks.Delete

  Next mysheet

  Set mysheet = Nothing
  Set shp = Nothing
End Sub

Any help would be appreciated!  I am sure it has something to do with Thisworkbook.sheets pointing to the personal.xls file rather than the spreadheet in question.
0
Comment
Question by:ASW3382
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
ID: 21751321
ThisWorkbook refers to the workbook containing the code (in this case, your add-in). Try this:

Sub CleanSheet()
Dim mysheet As Worksheet
Dim shp As Shape

  'Step through each sheet in the workbook
  For Each mysheet In ActiveWorkbook.Worksheets
     'Step through and delete each shape in the current sheet
    For Each shp In mysheet.Shapes
        shp.Delete
    Next shp
  'Remove all hyperlinks from the active sheet.
 mysheet.Hyperlinks.Delete

  Next mysheet

  Set mysheet = Nothing
  Set shp = Nothing
End Sub

Regards,
Rory
0
 
LVL 1

Author Comment

by:ASW3382
ID: 21751669
Worked great thanks!  I dont know my VB syntax so I fill file that away ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now