VBA function call from another open workbook

Spikenaylor

Board Regular
Joined
Apr 14, 2013
Messages
116
Office Version
  1. 365
Platform
  1. Windows
In workbook 1

Functions - module

Public Function Sheetpasswrd()
Sheetpasswrd = "1234"
End Function

VBA Project locked for viewing etc

In workbook 2

in a vba module

I am moving the data from workbook 2 into workbook 1 but I need to unlock the workbook 1

In workbook 2, i can within a cell retrieve the password

In VBA i am struggling to retrieve the password from the function in workbook 1

I have tried various solutions from the net but unsuccesfully

Workbook 2 module

dim wbk as Workbook, password as string

set wbk = Workbooks.open(Filename:= "Path to workbook 1)

wbk. activate

password = Application.run(wkb!Functions, Sheetpasswrd)

wbk.unprotect password:= password


I just keep coming up with errors

Can anyone point out my errors
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,

try changing this line

Code:
password = Application.run(wkb!Functions, Sheetpasswrd)

to this

Code:
password = Application.Run(wkb.Name & "!Sheetpasswrd")


and see if this does what you want.


Dave
 
Upvote 0
Further to the suggestion by dmt32
Should it be wbk, rather than wkb
 
Upvote 0
Modify your Sheetpasswrd function calling like this..

Code:
[COLOR=#0000cd]password= Application.Run("'" & wbk.Name & "'![/COLOR][COLOR=#0000cd]Sheetpasswrd")[/COLOR]
 
Upvote 0
Great
works
Thanks a lot
I didn't notice the spelling mistake
many thanks
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,456
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top