Paste excel link formula using vba - excel

I am working in an organization where we have 100s of excel files on our shared drive. These excel files contain asset numbers to our company assets in different cells within the files. What I would like to do is create a script in vba which would run only once and search through all these excel files using the find method and paste their cell addresses adjacent to their file path (I already have the paths of all the files in an excel sheet). But this address should in the form of a link formula, just like "=A2" so that we can later on modify this formula if there is a change in the position of the asset number without using vba. So suppose,
If cell E3 in the file1 contains asset number "XXX0000", the vba script should paste something like " ='\shared drive\folder path\file1.xlsx]WS'!$E$3 " in the cell next to the path,"\shared drive\folder\". So later on we can manually modify this formula if there is a change in its cell location
Thanks

Related

Excel, use file path to reference cell values in another workbook

I have a series of daily spreadsheets which are file by:
year / month / date
e.g.
/Users/myles/Dropbox (Green)/05_GM Vessels/Crew Dropbox/Green Isle/02_Daily Logs/2019 Logs/[GI_Daily_Log_30.07.2019.xlsx]Sheet1'!$B$44
I would like to use a formula to extract the value within the specified cell (B44 in this case) and show it in a master / summary spreadsheet.
The files are in a different directory to the master / summary spreadsheet.
I have a formula which generates the above file path based on values in other cells. E.G. ="["&$D$14&$W5&"/"&$A5&"]Sheet1'!$C$24"
Which creates the following text within a cell;
[/Users/mylesmetson/Dropbox (Green Marine)/05_GM Vessels/Crew Dropbox/Green Isle/02_Daily Logs/2019 Logs/7_July/[GI_Daily_Log_29.07.2019.xlsm]Sheet1'!$C$24
Ideally I would like to remove the first / and then insert " =' " which if pasted as text into a cell, would then extract the value from this spreadsheet file and the referenced cell. But this does not work. instead I am having to do this manually in notepad and then copy & paste the entire text back into the cell.
Finally prior to excel retrieving the number in the referenced cell, I have to give permission / find the file location.
This is quite a complicated thing to explain and I have not found any other solutions on the internet which are 100% relevant to this scenario. I think a macro may be required, but hopefully this can be done elsewise.
The indirect macro, would be ideal, apart from it requires the spreadsheets to be open, which is simply not practical either.
Thanks
for any help which can be provided.
Myles

hyperlinks to PDF files

I have an Excel spreadsheet in which I need to make hundreds of links to PDF files that are in the same folder on my computer.
The file name for the link appears in the Excel table.
Today I create each link separately, but I'm sure there is a simpler way to tell Excel to copy the link in the top box but look for the file whose name appears in the Excel table.
I'm doing each hyperlink separably
Assuming A1 has the name of the hyperlink and A2 has the location, use this formula where you want the link to appear:
=HYPERLINK(A1,A2)
You can then copy this down to the other cells.

EXCEL maintain hyperlink with the cell content after sorting/ using formula

INTRODUCTION
I have made a excel sheet of file index. Each file entry is linked with scanned copy of the file. So when i click the file name in excel sheet the linked PDF file opens.
ACTIVITY
In a separate worksheet i have made a search function based on multiple search results with partial matching. So when i enter part of either file name or subject i get the file name using
" =IF($F$1="","",IFERROR(INDEX(A$2:A$8,SMALL(IF(ISNUMBER(SEARCH($F$1,B$2:B$8)),ROW(B$2:B$8)-ROW(B$2)+1),ROWS(B$2:B2))),""))
"
PROBLEM
The file name obtained is plain text without the hyperlink associated with the file name in the master database.
WHAT HAS BEEN TRIED
I have tried using
(A) =IFERROR(HYPERLINK(.....))
(B) =HYPERLINK(CELL NUMBER)(By getting the row number from formula and using index function to reference the cell)
There is a tiny trick:
Insure the hyperlinks in the source column are formatted so that the "display name" is the URL. You can use either Inserted hyperlinks or the =HYPERLINK() worksheet function.
Say we have links in column A and we want an alphbetized list in column C. In B1 enter:
=LOOKUP(1,0/FREQUENCY(ROWS($1:1),COUNTIF($A$1:$A$3,"<="&$A$1:$A$3)),$A$1:$A$3)
and copy downward. (Column B is in alphabetic order, but the links are "cold") Then in C1 enter:
=HYPERLINK(B1,B1)
Even though the links in column B are "cold", the links in column C are "hot"

Copy cells from excel sheet and paste it to a DB query Sikuli

I am new to Sikuli. I need to copy data from excel sheets and paste them to a DB query using sikuli script. And how can I iterate among the excel cells to copy and paste the data repeatedly.
These data needs to copied and pasted one after the other.
It might be easier to copy all of the cells at once, then paste them one by one.
once Sikuli has opened Excel, you could do something like:
type(Key.HOME, KeyModifier.CTRL) #takes you to cell A1
type("a", KeyModifier.CTRL) #select all
type("c", KeyModifier.CTRL) #copy to clipboard
fromExcel = Env.GetClipboard().strip() #get clipboard contents into Sikuli, without leading or trailing white space
cells = fromExcel.split("/n") #split each cell into list on newline
#go to the destination app, maybe using App.open("nameOfYourApp") if it's not open yet, or App.focus("nameOfYourApp") if it is already open
for cell in cells: #use python to iterate through your list
#navigate to the line or cell where you want to paste
paste(cell)
Would something like that be of help?
Rather than providing a specific approach let's understand the options you have.
Simulate user keyboard actions (like it is described here by #autoKarma).
Excel sheet having a very specific structure allows you to detect some key points like first column and first row and then calculate other cells locations based on them.
You can try and use one of the Python Excel API libraries to access the excel sheet directly via API. If you only need to read the document and to to amend it, I believe this will be fairly easy to do.
Note: In all cases you will obviously have to think of how do you bring yourself to the point where you have an open Excel sheet on your screen and how to dispose of it when done.

Bookmark Special Paste, Excel look in same folder

I have a word doc and an excel doc, I have created bookmarks in word and special pasted into excel.....These bookmarks works AS LONG as the files stay in the ORIGINAL location (example- C:\Documents and Settings\My Documents\New Form)
BUT
I need to move the documents to different client locations (example- C:\Documents and Settings\My Documents\client1)
In excel the cell information reads like this;
=Word.Document.8|'C:\Documents and Settings\My Documents\NewForm\TestFactFind.doc'!'!Title'
Is there anything I can put so the excel file will look into its current folder to find the word document instead of a set location?
NON VBA Method
Yes it is possible for the Excel formula to pick up the value from a file from the same directory where the formula containing files reside. You have to use INDIRECT(). However a word of caution. INDIRECT will work only if the destination workbook is open.
Here is an example
Let's say the formula in Cell B1 in C:\Book1.xlsx is
='C:\Sample\[Sample.xls]Sheet1'!$A$1
Then put this formula in Cell C1 for testing it
=INDIRECT("'" & LEFT(CELL("filename",A1),FIND("[",CELL("filename",$A$1))-1)&"[Sample.xls]Sheet1'!$A$1")
Screenshot
I dont know about Word bookmarks, but I assume they are the same as Excel hyperlinks (?)
This may or may not be relevant in Word, but in excel you can create a link to any other document using the hyperlink formula. If you use the current directory (folder) as the root, it will go from there.
".\" is the current folder
"..\" is the parent folder that the current folder is in
So lets say you have an excel sheet with links to 20 Word documents stored in a subfolder called REPORTS (excel to word being the reverse of what you proposed, but it is probably the same the other way around?).
The links in each excel cell would be:
=HYPERLINK(".\REPORTS\JAN.DOC","January report")
=HYPERLINK(".\REPORTS\FEB.DOC","February report")
=HYPERLINK(".\REPORTS\MAR.DOC","March report")
etc...
A feature I use often is to have the filenames, or part of the filenames, listed in an excel column parellel to the links, and use that cell in the hyperlink filename. Take the following example, and assume it to be range A1:B4 (Line 1 being the column headers "month number" and "link to report").
In this example, I named my word documents MONTHxx.DOC, xx being the month number.
MONTH NUMBER LINK TO REPORT
01 =HYPERLINK(".\REPORTS\MONTH" & A2 & ".DOC","Report for month " & A2)
02 =HYPERLINK(".\REPORTS\MONTH" & A3 & ".DOC","Report for month " & A3)
03 =HYPERLINK(".\REPORTS\MONTH" & A4 & ".DOC","Report for month " & A4)
etc
Having the cell at the end in the second part of the hyperlink puts the month number also in the name of the link for the user to see. You can, of course, use any cell there to put a name.
The beauty of this method is that if you have, say, a list of 500 files to link to, and they are all numbered in sequence (like the example), you can just copy-paste the first hyperlink all the way down the column which will instantly give you 500 links to other documents.
Just FYI, the documents do not need to be open already. Clicking the link will open the linked document.
I know this is not what you asked about, but it is fairly close. Hope it helped.

Resources