• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2936
  • Last Modified:

Break all links via VBA and save file

Hi,

I have linked some charts from an excel workbook, I would like to have a button (non printable) that would break all links and save the filename as todays date, is this possible?

Thanks!
0
sanjshah12
Asked:
sanjshah12
  • 4
  • 3
  • 3
  • +2
2 Solutions
 
MaduKpCommented:
Below thread will be help to get an idea about removing links before save

http://www.eggheadcafe.com/software/aspnet/32671218/button-to-break-links-delete-all-vba-code--save-as.aspx

0
 
GrahamSkanRetiredCommented:
You can use a macro like this, but a non-printable button is more problematic.

You could use a Macrobutton and set its font attribute to Hidden, and make sure that the option to view hidden text is set and the option to print hidden text is not set.

Ideally the button should be on a toolbar, and not the document. Which version of Word are you using?
Sub UnlinkAndSaveAsDate()
    ActiveDocument.Fields.Unlink
    ActiveDocument.SaveAs "C:\MyFolder\" & Format$(Now, "YYYY_MM_DD") & ".doc"
End Sub

Open in new window

0
 
sanjshah12Author Commented:
Graham, thanks for your code, I've added the following code to break the links, but could you please give me some more information/direction on how to create a non printing button.

I'm using Word 2003

Thanks.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Chris BottomleySoftware Quality Lead EngineerCommented:
For a button - how about one in the menu area?

1. Assuming a macro like UnlinkAndSaveAsDate exists in a normal module of normal.dot, (to make sure it's always available) then

2. Right click the menu area and select customise
3. toolbars | New make available in normal.dot
4. OK | Drag the appropriate menu into the menu area
5. Commands | MAcros
6. Find UnlinkAndSaveAsDate and drag it onto your new toolbar
7. Right click the button and in the name field make it more meaningful to you

Chris
0
 
Richard QuadlingSenior Software DeveloperCommented:
I have created an Excel Addin (.xla file) which adds the ability to export the data from a spreadsheet to a file suitable to be included into a PHP script. We use this to quickly get the data into the accounts system.

I've attached the addin and removed the payload.

Depending upon how many users you want to give this facility to, you may want to look at using something like AD or GP to set a network level directory for addins. Otherwise you can copy the file to the user's addins folder and tell Excel to open it.

Upgrading an addin is just a case of making sure no one is using it and overwriting 1 file. No need to revisit each user.



Export-Spreadsheet.xla
0
 
Richard QuadlingSenior Software DeveloperCommented:
Doh. And now I realise you are talking about Word.

I'd guess you should be able to convert the macros in the xla to something that word can handle and then save that in the startup folder of Word.

What is interesting is that Word doesn't seem to have a global Startup - one to share amongst all users - as well as one for the user.

0
 
sanjshah12Author Commented:
Thanks RQuadling,  for your messages, I'll keep that file in case I need it later.

Thanks Chris for your steps to create a button on the toolbar, doe sthis mean unlike Excel where you can create a button on the fly via VBS this is not possible in Word?

Thanks
0
 
Richard QuadlingSenior Software DeveloperCommented:
You can do the same in Word VBA as I do in Excel VBA. I've just never done it.

I'd have to do some work on when to run the "add button" code and when to run the "remove button" code.

You don't want the button there when you close word as the menus are remembered.

I think it is something like Auto_Open and Auto_Close macros.

In reading about Word Addins, they are .dot file (yep, like templates - so stupid!!!!).

http://www.msoffice-tutorial-training.com/word-add-in.html

0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Yes indeed you can create them on the fly ... i.e for a specific document if that is what you want just say.

Chris
0
 
sanjshah12Author Commented:
Yes, let me explain better, I have a document already prepared if I can add a button to this document that breaks all links (I can do this now from Graham's post above). Now when the user clicks the button I would like to remove the button and after executng the macro.

Hope this makes sense.

0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
The following for example will create the menu when the document is opened and remove it either when the document closes or the button is pressed - whichever occurs first.

Chris
'thisWorkbook CodePAge
Private Sub Document_Close()
    killBar
End Sub

Private Sub Document_Open()
    buttonAdd
End Sub

'Code Module
Sub buttonAdd()
Dim btn As CommandBarButton
Dim crbmenu As CommandBar

    With CommandBars("Menu Bar").Controls.Add(Type:=msoControlPopup, Temporary:=True)
        .Caption = "My Menu"
        .Visible = True
        With .Controls.Add(Type:=msoControlButton)
            .Caption = "My Button"
            .OnAction = "UnlinkAndSaveAsDate"
            .Enabled = True
        End With
    End With
End Sub
Sub UnlinkAndSaveAsDate()
'    ActiveDocument.Fields.Unlink
'    ActiveDocument.SaveAs "C:\MyFolder\" & Format$(Now, "YYYY_MM_DD") & ".doc"
    killBar
End Sub

Sub killBar()
    On Error Resume Next
    CommandBars("Menu Bar").Controls("My Menu").Delete
    On Error GoTo 0
End Sub

Open in new window

0
 
GrahamSkanRetiredCommented:
You could consider creating a shortcut key combination to run the macro.

Click KeyBoard... on the Customise dialogue.

Select Macros in the Categories box, and highlight your macro in the right-hand box. Enter your keystrokes, starting with Ctrl or Alt, keeping the key(s) depressed until a character or a function key is hit. If you choose a shortcut already in use, the command will be shown after the 'Currently assigned to': label.
0
 
sanjshah12Author Commented:
Chris,

That's perfect - thanks for your help.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now