[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2008-06-10
2
Medium Priority
?
386 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

649 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