Solved

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

Posted on 2008-06-10
2
364 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 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

19 Experts available now in Live!

Get 1:1 Help Now