Deleting hidden name definitions with invalid names in Excel 2003 - excel

I am using this macro:
http://support.microsoft.com/kb/119826
to try and clean up hidden names in my excel file. It works for most of the hidden names, but not for a few _123Graph names. I'm not sure where these names came from, but when I try to delete them I get a 1004 automation error.
The knowledge base mentions that names with spaces may cause an error. Is there a way to delete these?

Excel 2007 and above resolves this issue... but a quick fix for Excel 2003 is:
Go to the Tools Menu
- Options
- General tab
- Check R1C1 Reference Style
Then hit "Ok".
You will then be prompted for a new name for each of the corrupted names.
...then you can go back and uncheck the R1C1 check box.

I use the excellent Name Manager add-in to, erm, manage the named ranges in my workbooks, including all those pesky ones like the example you give that are automatically created by Excel when autofiltering etc. which aren't normally exposed.
It allows filtering of names by type, location, scope etc. and generally knocks the awful built-in dialog into next week.
Edit: If installing an add-in is out of the question then adding the following code in a standard module will allow you to loop through the names in the workbook and delete the offending items.
Sub deleteNamedRanges()
Dim n As Name
Dim a As Variant
For Each n In ThisWorkbook.Names
a = MsgBox("Do you want to delete the following name?:" & vbCrLf & vbCrLf & n.Name & " (" & n.RefersTo & ")", vbYesNo, "Delete ranges")
If a = vbYes Then
n.Delete
End If
Next n
End Sub
If there are a great many names then you should be able to modify this to suit your needs.

Related

How to create hyperlinks with VBA to the same open workbook

The setup
I have an Excel workbook stored on my hard drive.
The structure is such that on the first sheet I have a list of the names of the other sheets in the same workbook (...which can be created or deleted).
All the names on the list, on the first sheet, are supposed to be hyperlinks to the corresponding sheet in the workbook. So, by clicking the name on the first sheet you jump to the corresponding sheet.
When a new sheet is created a macro creates also the new name on the list on the first sheet and makes a hypelink of it. This works.
...BUT...
The links point to the stored version of the file, not to the open workbook! Clicking the links opens the stored file and not the one which is under work.
QUESTION: How to create a hyperlink that always points to the same open workbook and not to the stored copy of it?
Try this:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"Sheet3!", TextToDisplay:="Link to sheet #3"
Address is the URL and SubAddress is a localtion of the page (or a sheet or a range in excel workbooks).
You may try creating the hyperlink as a formula (via VBA, as you need).
I am using the parameters you posted, this may need a little adjustment.
Dim rngsrc as Range, rngtrgs as String
Set rngsrc = Worksheets("Summary").Cells(Cell.Row, 5)
Set rngtrg = "'" & sSheetName & "'!B5"
rngsrc.FormulaR1C1 = "=HYPERLINK(" & rngtrgs & "," & sSheetName & ")"
See
Official documentation
Example 1
Example 2
This (hopefully) answers your question. As a separate note, it still remains to be clarified why you see the behavior you see.
It seems that the problem comes from the following fact: My file is in a SharePoint folder. If I open it just for reading, the hyperlinks work fine. If I open the file for editing, a copy of the SharePoint file is placed on my hard disk, on a specified location. So, the path to the file is not the same as it would be if I open it read-only. Should I use hyperlink.follow to solve this?
So, this all comes down to the question: In VBA/Excel, can I create a hyperlink which always points to a location in the same opened file so that the hyperlink ignores the storage path of the corresponding file? Using empty string (or BLANK) doesn't help as the address parameter in hypelinks.add as Excel seems to automatically fill in the whole storage path.
I upgraded to Office 2013 and "PADAM": The problem vanished! It seems that there was a bug in Excel/VBA in this in the 2007 version.

Update a named range in excel (and all references to it)?

I used a period (.) in all my range names, which is fine for excel but not fine when I try to export to a google spreadsheet.
Is there an easy way to update all my range names (replace . with _ )? Copy&replace only handles the references and not the names themselves.
Or, in this case, another solution would be to replace name references with their normal table location (C5 etc..), the reverse of apply names. Is there a quick way to do that?
VBA will be helpful in this situation. Please do the following:
open the workbook you have problem with
go to VBA Editor/IDE by pressing Alt+F11 in Excel app
in IDE >> Menu >> Insert >> Module
in code window (the biggest one) add the following code:
Sub qReplace()
Dim myName As Name
For Each myName In ActiveWorkbook.Names
myName.Name = Replace(myName.Name, ".", "_")
Next
End Sub
click inside it and press F5
Should work which I tried and tested.
I recommend Jan Karel Pieterse's Name Manager addin. It's one of the great Excel development tools and, more specific to your needs, has a rename function that offers to update references throughout the workbook and code.
Of course, be sure to back up your work before doing something like this.

How to copy ALL data from 12 workbooks onto a blank one / Range Inquiry

I am almost completely new to using VBA and Macros on Excel 2010. I know little to nothing about macro coding, and I just started a day ago trying to pick it up.
I was asked to create a macro that copies ONLY the data from 12 workbooks and pastes it onto a blank workbook (they all have 1 sheet each, with the data on each workbook starting on cell A3 while stretching to column S (the amount of data on the sheets vary)).
NOTE: When I mean "ONLY the data," the cells that I want to be copied include the blank cells that are in between the first and last parts of the data.
1) When copying data from one workbook to another, do you HAVE to specify the cells that you would like to copy? Or is there a way to specify where the data ends on the sheet, and then copy all of that data? If so, then could someone show me how to do so? The reason for doing so is because the macro will be used weekly.
and 2) Could someone simply help me develop this macro? Help would be massively appreciated :)
Some Extra Notes:
- The Workbooks are named "Status by offering ID [1-12]
Thanks again!
Ripster has given one example of missing information from your specification.
Santosh recommends a pretty neat tool but my reading of your question is that your knowledge is not up to using a tool yet.
I deduce this is a work question and your boss has asked you to write this macro despite your knowledge of VBA being zero. This seems to be a growing problem: you can discover the answer to anything on the net so why bother with training people. Even if you produced a complete specification of your requirement, I doubt anyone will give you a complete solution. If they do provide a complete solution, it will not help with the next requirement. So I am going to break your problem down into the type of questions you can ask the net.
Each week you get 12 source workbooks and create a summary by consolidating data from the source workbooks. Do you overwrite the previous week's summary with the new summary or do you want to save all the summaries? It will not add much to the complexity to keep all the summaries but you need to decide what you want.
If you discard the previous summary, the macro can be in Summary.xlxm, say. If you save the summaries, the macro will need to be in its own workbook, Macro.xlsm say, and it will create a different summary workbook, SummaryYYWW.xlsm say, each week.
If you search for "Workbook Open" and "Workbook Create", you will find instructions on how a macro in one workbook can open other workbooks and create new workbooks.
Where are the source workbooks? Are they in the folder CurrentData which is overwritten each week? Are they in the folders Week1301, Week1302, Week1303 and so on? Are they in the folder NewData and the macro is to move them to folders Week1301, Week1302, Week1303 and so on after processing? All these are options but I suggest you start by moving the source and summary workbooks to/from a folder convenient for the macro.
Look up "ThisWorkbook" and "ActiveWorkbook". In brief: "ThisWorkbook" is the workbook containing the macro and "ActiveWorkbook" is the most recently opened workbook.
Look up workbook property "Path". ThisWorkbook.Path, for example, gives you the name of the folder containing ThisWorkbook. Look up workbook property "Name".
If the source workbooks always have the same names, you could hard code the names into the macro. I do not recommend this. Look up the function "Dir".
I hope the above has given you a start on breaking your total problem down into its components.
There are many different VBA tutorials available on the web. Try a few and pick one you like.
"Debug.Print xxx" outputs the value of xxx to the Immediate Window. This can be very helpful as you start. Try this as your first macro:
Option Explicit
Sub First()
Dim FilenameCrnt As String
Dim WbookCrnt As Workbook
Debug.Print ThisWorkbook.Name
Debug.Print ThisWorkbook.Path
FilenameCrnt = Dir$(ThisWorkbook.Path & "\*.*")
Do While FilenameCrnt <> ""
Debug.Print FilenameCrnt
If FilenameCrnt = ThisWorkbook.Name Then
With ThisWorkbook
Debug.Print " Used range: " & .Worksheets(1).UsedRange.Address
End With
Else
If LCase(Right(FilenameCrnt, 3)) = "xls" Or _
LCase(Right(FilenameCrnt, 4)) = "xlsm" Or _
LCase(Right(FilenameCrnt, 4)) = "xlsx" Then
WbookCrnt = Workbooks.Open(ThisWorkbook.Path & "\" & FilenameCrnt)
With WbookCrnt
Debug.Print " Used range: " & .Worksheets(1).UsedRange.Address
End With
WbookCrnt.Close
WbookCrnt = Nothing ' Free resource
End If
End If
FilenameCrnt = Dir$
Loop
End Sub
Best of luck

Possibility to use hyperlinks in a shared excel workbook

I've got an excel document where we've enabled the "Track Changes" functionality in order to capture whose changes what and when - for this you'd have to share the workbook.
We've now found that we want to make it a bit easier to navigate in the file (as it's getting quite big) - and in this process we'd like to make use of hyperlinks between tabs.
Now I've looked around a bit to find out how to do this - because as you may know Excel doesn't allow you to use hyperlinks when the workbook is shared (at least not that I know of) - and I don't want to - unshare workbook > insert hyperlink > reshare - as that means losing the tracking we've made so far :(
I've been able to find an answer stating:
In the Formula Bar for the cell you want the link in, use the following formula:
=HYPERLINK("url_goes_here", "cell_content_here")
Now I've tried inserting something like this:
=HYPERLINK("'CHANGE LOG'!"; "CHANGE LOG") and alternatively
=HYPERLINK("'CHANGE LOG'"; "CHANGE LOG")
It does truly insert a hyperlink but I just get an error message stating "cannot open the specified file."
Is anyone aware of a workaround or able to tell if I'm doing something completely wrong?
Br, Thomas
Several other sites suggests to unshare, add links and then reshare the workbook but this is somewhat annoying because it prevents users that currently have it open from properly saving if you unshare while they have it open even if you reshare before they save.
No need to unshare then reshare just set the cell's Formula property to equal to =HYPERLINK(link, text)
Sheets(targetSheet).Range(targetRange).Formula = _
"=HYPERLINK(" & Chr(34) & "http://www.google.ca/" & Chr(34) & ", " _
& Chr(34) & "Click to go to google" & Chr(34) & ")"
Chr(34) are double quotes
The result formula is =HYPERLINK("http://www.google.ca/", "Click to go to google")
This is the workaround in VBA to allow hyperlinks in shared workbooks.
Sorry that this probably doesn't completely answer OP's question but this was the only SO topic regarding this problem so I thought I'd share in case anyone else stumbles here.
Try with this http://office.microsoft.com/en-001/excel-help/hyperlink-function-HP010342583.aspx
Section: Jump to a specific cell on a worksheet

Refer to Excel workbook by path, based on cell value data

I have an Excel sheet that draws data from other, closed Excel workbooks. Currently it works fine when I list out the closed workbook's entire path, but I'd like to use a variable, stored in a separate cell, as part of the path name.
For example, I am trying to reference a workbook called
workbook12.10.12.xls
In a separate workbook (we'll say the "active" workbook), I have a cell with formula
=INDEX('C:\Path[workbook12.10.12.xls]SHEET1'!$B$1:$B$5, MATCH("match text", 'C:\Path[workbook12.10.12.xls]SHEET1'!$A$1:$A$5, 0))
which finds the value in workbook12.10.12's B column corresponding to the cell in the A column that contains "match text." This works fine; however, I have a cell in the active workbook with the value
12.10.12
and would like to somehow reference this value in the INDEX function.
I can't have the other workbooks open, so the INDIRECT function won't help. Googling seems to suggest that Excel doesn't have a simple one-stop solution for this kind of thing... can someone help please? Thanks!
From Frank Kabel's 2004 post at Dicks Blog you could
Use Laurent Longre has developed the free add-in MOREFUNC.XLL which includes the function INDIRECT.EXT
Use SQL.REQUEST as described here *does not appear to be supported anymore and I am not clear if this could handle your INDEX\MATCH request
Use Harlan Grove’s PULL function
In addition you could:
Create a "dirty link" directly via code that enters a formula referring to the workbook you need
For pulling values - but not for working with ranges - you could use Walkenbach's ExecuteExcel4Macro XLM method
I think what you what to do is to find the specific record in the specific file (date named).
You may do it by a simple VBA code.
Suppose you are going to search for a record# say REC001 in A1, date file 12.10.12 at cell C1, and have the result to be display at cell A7
On the worksheet you want to enter input and get output, rightclick the sheet tab and select 'View code' and paste the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C1")) Is Nothing Then Exit Sub
Range("A7").Formula = "=INDEX('C:\TEMP\[workbook" & Range("C5").Value & ".xls]SHEET1'!$B$1:$B$5, MATCH(" & Range("A1").Value & ", 'C:\TEMP\[workbook" & Range("C5").Value & ".xls]SHEET1'!$A$1:$A$5, 0))"
End Sub
Then every time you edit C1, the formula will be updated.
Actually I don't think you should use INDEX function in your case. It is more simple to use a VLOOKUP. E.g.:
Range("A8").Formula = "=vlookup(" & Range("A1").Value & ",'C:\TEMP\[workbook" & Range("C5").Value & ".xls]SHEET1'!$A$1:$B$5,2,false)"
You will have to note on a few points:
1. you paste the code on the Sheet1 object (or the sheet name) but not to insert a new module
2. your path and filename for the target file is correct, including the .xls and .xlsx
3. your original file only cover to $B$5
4. on VBA, recommend you to save the file as .xlsm format
You can store a full reference including the file path to a range in a closed file in a name in excel (either directly or via VBA based on selections in different cells and using the Worksheet_Change procedure as above) and then refer to the file using the name in a formula as normal. This gets over the limitation in the INDIRECT function.
The VBA is very simple:
New_Ref = Sheets("Wells").Range("K6")
ActiveWorkbook.Names("MyWorkbook").RefersTo = "=" & New_Ref
The only trick is to be sure to include "=" in the name.
Names have a huge number of uses once you spot this. I have used this to get data from a closed file on a remote sharepoint site without any difficulty - I assume sharepoint deals with all the permissions.

Resources