Solved

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

Posted on 2008-06-10
2
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

740 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