I have two workbooks. Say test1.xlsx and test2.xlsx and have saved them in the same directory.
I write a formula to create an external link in cell A1 of sheet1 of test2.xlsx.
Example:
In the A1 cell of sheet1 of test2.xlsx I write =[test1.xlsx]Sheet1!A1 and press enter. It copies the corresponding cell content of test1.xlsx into test2.xlsx
I don't want this formula to be executed. I want that my workbook "test1.xlsx" shouldn't be accessed by any other external workbook i.e. no one can provide an external reference to test1.xlsx and if provided, it should return any error say "!#REF"
I am using Excel 2010.
It will be quite helpful for me to know exactly what are the events taking place in test1.xlsx
Not exactly the behavior requested, but you could do this:
Password-protect test1. The user will be prompted for the password when the formula is entered.
If the password is correctly entered, the formula(s) will execute, but the users will be prompted for the password to update links each time test2 is opened.
Related
Not sure if relevant for solution, but just so you see the workflow, file is set up as follows:
One sheet is called "Template".
User enters info on another sheet called "Enter Info".
Click on cmdbutton "open client" and the assigned macro copies the sheet "Template" and renames it using certain data (client name) from the "Enter Info" sheet.
This all works fine.
In the "Template" sheet (which gets copied) I have 2 command buttons and have assigned a macro. The macro is saved "in this worksheet".
Example: "Filename.xls!macro_do_something"
This has worked for 2 years now, but all of a sudden every single button in every single sheet (not just new copies) has been assigned to the macro:
"Filename comp.xls!macro_do_something"
When I click to execute the command I get the message that the file could not be found, which makes sense as it does not exist and never has.
I have never copied the file to a different location, I have never changed the file name. It worked fine and correct for 2 years.
Any ideas how this can happen?? Why would the file name just randomly get changed??
As you've been cloning sheets for two years, the workbook could have reached some maximum number of sheets. Some magical 32, 64, 512 etc. Perhaps reaching such a limit would produce an unexpected behaviour, like changing the file name in the buttons assignment.
One other thing you could check for is the presence of a special character in the sheet names the workbook assigns after the client names.
I'm uploading an excel file that contains sheets, to my server which encodes to base 64 so I decode it as required and process it by adding data in sheet 5 as column1 and column2 with certain number of rows. At the time of uploading, this sheet has some specific formulas on sheet 5 that makes changes in other sheets. So on opening the file which I send as response after editing from server, There comes this prompt that reads
"Excel Found unreadable content in 'MyDownloadedExcelData.xlsx'. Do you want to recover the contents of this workbook?If you trust the source of this workbook, click Yes', with Yes and no buttons
and when I click on yes and open the sheet, all the formulas are deleted.
I see something like
Excel was able to open the file by repairing ot removing the unreadable content.
Removed Records :Formula from /xl/calcChain.xml Part
Repaired Records : Cell Information from /xl/worksheets/sheet1.xml part etc
So, How do I make sure my formulas in the sheet are retained?
Using VBA you could have an on close event that pastes values and an on open event that recreates the formulas. Your file would essentially save with static data, but then be used with functions intact.
If this solution is of interest I can help provide some coding framework.
Example:
A B
1 =vlookup(XX)
2
3
in cell A1 there is a Vlookup formula, Is it possible to enable user entry in this cell and override the formula then later restore the formula automatically when sheet is open again?
Even through VBA
Short, boring answer: nope.
A cell only ever has a keyed-in value, or a calculated formula. Can't have both.
Longer answer: maybe.
Shift everything 1 row down, and use row 1 to store your "original" formula - then hide that row (and pray the user isn't going to mess with it).
When the sheet is opened again sounds like you're confusing "workbook" and "worksheet" - you need to handle Workbook_Open if you want to run code when a workbook opens. Workbooks contain worksheets - it's the workbook that opens, not the sheets (sheets activate, but I doubt you would want to put that logic in there).
So, in the handler for Workbook_Open, write code that takes the formula in the hidden row and overwrites whatever is under it.
Another solution can be to hard-code the formula in the VBA code.
One possibility would be to store your Workbook as a template. Normally when a user opens the workbook by double-clicking, it will open whole new workbook based on the template, and they can modify it to their heart's content, save it, mail it to Grandma, etc.
The next person who comes along will double-click the template file and get the formula again, just as you designed it.
Short answer: Kind of, sort of
Long answer:
Save your workbook as a template. Every time someone will use it you'll see the orignal with formula, then if someone write over the formula, when using save your original will be kept intact.
What You need to do is:
press Alt + F11
select ThisWorkbook and paste this code:
Private Sub Workbook_Open()
Worksheets("Sheet1").Range("A11").Value = "asdf"
End Sub
Every time the workbook is opened, this script will run.
Instead of "Sheet1" you can write the name of the sheet you want to apply the script.
Inside the Range, You can define the cells you want to modify, You can use even multiple cells. Check this for more information about this.
After Value You can write what You want to be written inside the cell. You can write "=vlookup(XX)" and it will work.
I have a worksheet with a table in, that I have protected via a password I have defined.
I also have some VBA code running under the Worksheet_SelectionChange event which checks if the current cell is within the table, if yes it unprotects the sheet and if no it reprotects the sheet with my predfined password.
I am aware though that when inside the table (hence unprotected) the user could enter a new password for the sheet protection which will cause an error to the running of the macro.
Does anybody know if it is possible and if so how to capture the password a user enters into the sheet, that I could store into a VBA variable?
My thinking is that I could then run something further to unprotect instantly with that password and then reprotect withmy predifined one?
Thanks
Say I had two Excel sheets (ONE.xlsx & TWO.xlsx). Would it be possible to have a certain cell in ONE to be changed at the same time as a certain cell in TWO?
For example:
B2 in ONE is equal to "Tuesday". Is there a way to make D10 in TWO also equal to "Tuesday" without having to go into TWO and manually changing it.
The more I think about this problem the more I think that it's not likley to work. The only way I can think of it working is by connecting them both up to the same database somehow. Thought I'd try you guys before I give up try something else.
Thanks in advance!
I've found a solution that works very well.
Open both the workbooks.
In the source workbook, copy the cell(s) that you wish to link.
In the destination workbook, right click and select "Paste Link".
The cells in the destination workbook should now be linked so that when changes are made to the source workbook the changes are also made in the destination workbook.
Sure, open both workbooks.
put = in workbook 2 minimize and find the sheet/cell in workbook one
select it.
close workbook 2 and save.
change the value in workbook 1
open workbook to (enable the security to look at workbook 1)
see the updated value.