XML sheet names not seeming to agree with vba worksheet names - vba

I have a large bloated workbook.
I've made the file a zip and opened the zip to inspect the xml files. Then I've looked at the worksheets folder in the zip to see this:
If I then look in the vba editor I can see this:
But "Sheet25" in the vba is a tab for notes with only 5 lines of text on it so these names are not the same.
Is there an easy way for me to map between the two different identifiers? e.g. what Sheet is sheet25.xml?

The simplest check is to open sheet25.xml. You will see the matching codeName in this line at the top:
<sheetPr codeName="Sheet22"/>
EDIT:
If you don't want to open the xml file (because it's too big), there is another way you can trace the mapping of the xml sheet filenames to the codeNames of the sheets in the workbook.
Open up the xl/_rels/workbook.xml.rels document. You should see lines like this:
<Relationship Target="worksheets/sheet3.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId3"/>
<Relationship Target="worksheets/sheet2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId2"/>
<Relationship Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId1"/>
Link the xml sheet name to its resource ID on the far right, e.g.,
worksheets/sheet2.xml => Id="rId2"
Then open up the xl/workbook.xml document, where you get:
<sheet r:id="rId1" sheetId="1" name="one"/>
<sheet r:id="rId2" sheetId="3" name="Sheet3"/>
<sheet r:id="rId3" sheetId="4" name="Sheet1"/>
Link the resource ID to the sheet name, e.g.,
r:id="rId2" => name="Sheet3"
And then from the VBE editor:
Sheet3 (Sheet3)
Match the name to the tab name inside the parentheses to get the codeName:
Sheet3 <= (Sheet3)
Done.

I think that the sheet number of the xml file is just the order of the sheet in the workbook counting from the left at the point at which you saved the file. To find it you can open your spreadsheet and unhide all sheets. Alternatively you can use the formula =SHEET() in a worksheet to identify its number.
Note that this is different to the sheetcode in VBA which is a permanent sheet number that you see if you open the project explorer in VBA. The sheetcode will not change if you move it around.

Related

Point to the Excel sheet where the Macro actually stored

I have a sheet named "State List Generation" in which I have written a code which can extract City and State list from some text. I wanted to run this macro in another sheet which contains the text. I will be able to run this through macro window of excel if the first file is open. The problem is my state and city list is in the first sheet (State List Generation). When i run the macro from the second sheet which has data, the second sheet becomes the active sheet!!. I am not able to point the first excel where the the actual macro is present. Is there any way??
I have found the answer from https://support.microsoft.com/en-us/help/291308/how-to-select-cells-ranges-by-using-visual-basic-procedures-in-excel
I have just used Workbooks("FT_State_update.xlsm") to point the particular workbook. Thanks to Maddy Nikam

Importing data into a master worksheet

I have a doubt about my program to the VBA/EXCEL
I made a file called "MASTER WORKSHEET" with various data from a client, my goal is: To create a VBA to open any file in Excel and that I import chosen cells to fill out all data of the "MASTER WORKSHEET", for example, all excel file I open with the button "IMPORT DATA", it will automatically capture only those cells that I choose, but my program it captures but is with configuration problems on VALUE or NUMBER.
If your question is simply "how do I copy a cell from one place to another", an example would be:
Workbooks("Input Workbook").Worksheets("Input Worksheet").Range("J1").Copy(Workbooks("Master Workbook").Worksheets("Master Worksheet").Range("A4"))
If you just want to copy the value, without the formula and formatting, you could use
Workbooks("Master Workbook").Worksheets("Master Worksheet").Range("A4").Value = Workbooks("Input Workbook").Worksheets("Input Worksheet").Range("J1").Value
Obviously, the workbook, sheet, and range names need to be changed to your particular situation.

copying worksheet values from one workbook to another vb.net without formula links

Using vb.net. we want to copy several worksheets from one file into another file. we have it looping and copying which ones we have going by
xlWorksheetSource.Copy(After:=xlWorkbookDestination.Worksheets(xlWorkbookDestination.Worksheets.Count))
for example... but i noticed when i open up the file that was created.. in some of the columns it has links that reference the original file for formulas... how can you just have it so it copies the values and doesn't reference the original file in formulas that it copied.
You probably need to do something like this
xlWorksheetSource.PasteSpecial(xlPasteValues, xlPasteSpecialOperationNone, False, False)
For more information use this link:
ExcelPasteSpecial

Excel VBA: How to create multiple Excel files using a single Excel template

My requirement is simple:
I have a list of filename in column A:A200 of Sheet1 of Book1 and an Excel Book2 which is a readymade template with 6 sheets.
I need to create or rather replicate this excel Book2, by changing the file name of the template excel to the names I have in column A:A200 of sheet1 of Book1.
Also a small functionality would be that the same name (name of the Excel or the name present in the column A) should be added to Sheet1, cell B5 of the new sheet.
So basically I have to make copies of an excel template and rename them according to my list and also change a value in the new sheet as the name of the Excel.
Am sure many users would have wanted this simple functionality, so any small VBA code, or reference to any code already present would be helpful.
Check out the example here
You can Down load the zipped Folder there as well to test and work with the code.

Update hyperlinks in shapes when file location changes

I have a process flow diagram that uses various excel shapes to visually represent a data production process from start to finish, I.e. from data input to analytic environment to data output to submission file. I have used vba to hyperlink many of the shapes in the diagram to another sheet in the workbook (using thisworkbook.fullname) that contains definitions for abbreviations contained in the text of each shape, eg C1 is listed in a shape, the hyperlink takes you to the definition tab cell where C1 is defined as control point one. The hyperlinks work when the xlsm workbook is in my home location where i saved the file but they do not work if I save the file to another location (they try to open my original workbook). Is it as easy as changing the hyperlink addresses to thisworkbook.filename and dropping the path to make this work? do i need to create a macro that will automatically look up the old hyperlink address and replace it with the new address of current file location for every shape in the workbook containing a hyperlink. The path could change in the future, so want it to be relative and not fixed - for example if I save the file to share point and another user saves a copy to their home directory, I still want the links to work for them in either location. Some hyperlinks go to "sheet1" some to "sheet2" for example, but sheets 1 & 2 are both located in the same workbook. Please help!
ActiveWorkbook.Name solves the problem, replace ThisWorkbook.FullName with it and hyperlink works in other directories.