Set workbook name not working
You can..
Private Sub Start_Click()
Call ReskontroArk("Kunder", ActiveWorkbook.Name)
End Sub
Private Sub ReskontroArk(ReskontroType, strWb As String)
MsgBox Workbooks(strWb).Name
End Sub
--
Jacob
"JayDe" wrote:
Thank you Jacob, this worked.
I am howewer using several WorkBooks in my macro, and I try to avoid using
ActiveWorkbook, and instead assign a variable name to the WorkBook I am
working on. Could I used a variable in the call procedure, instead of the
ActiveWorkbook
Regards
JayDe
Norway
"Jacob Skaria" wrote:
Hi
I am unable to recreate an error..The code looks fine.
Few other points
--Set MalWb = Workbooks(ActiveWorkbook.Name)
is same as
Set MalWb = ActiveWorkbook
--To re-write your code the below would do. The procedure ReskontroArk takes
the second argument as a workbook object instead of string variable
Private Sub Start_Click()
Call ReskontroArk("Kunder", ActiveWorkbook)
End Sub
Private Sub ReskontroArk(ReskontroType, MalWb As Workbook)
MsgBox MalWb.Name
End Sub
--
Jacob
"JayDe" wrote:
Hi
I am trying to set the workbookname in a sub procedure but it is not working.
Her are the part from my code that is not working:
Private Sub Start_Click()
Dim MalWb as workbook
Dim MalTxt as String
Set MalWb = Workbooks(ActiveWorkbook.Name)
MalTxt = ActiveWorkbook.Name
' Here I have som code to put data into MalWb
Call ReskontroArk("Kunder", MalTxt)
End Sub
Private Sub ReskontroArk(ReskontroType, MalTxt As Variant)
Dim MalWb As Workbook
Set MalWb = Workbooks(MalTxt) ' run time error 1004. Canot find file
End Sub
Can someone see what I have done wrong
|