I have 2 spreadsheets, EG. test1.xlxs and test2.xlsm
test1 has the following data on sheet 1 cell B6: testdata
test2 has some vba code I want to disable if test1 is not present or has the wrong information in it, as such, I need to use an environmental variable in the VBA IF statement that that I don't have to edit the code or re link the sheets every time I move them to a new pc
The problem I have is, when I use the environmental variable The If statement tests against the string and not the cell value EG "=C:\users\username\documents[test.xlxs]Sheet1'!$B$6" instead of testdata
This is the code I currently have in test2:
Sub Check_Key()
Dim Key As String
Key = "='" & Environ("USERPROFILE") & "\Documents\[test.xlxs]Sheet1'!$B$6"
If Key = Sheet1.Range("D8") = True Then
Sheet1.Range("D9") = "Valid"
Else
Sheet1.Range("D9") = "Invalid"
End If
End Sub
is there any way to make it work? I would prefer to have the VBA script do the verification rather than an if statement in a cell on the workbook
Requirements: User should not be able to see data in test1 (spreadsheet should stay closed) Data from test1 needs to be verified via VBA IF statement test2 should be able to be anywhere on pc while test1 should be in my documents
Here is a link to the Spreadsheets, it includes the Licence file the test sheet and a key generator Documents
If the test1 is already open in the same excel instance :
If he is not
The following code copies the value in cell B6 from the closed workbook.