Solved

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

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 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