Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Set workbook name not working

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Set workbook name not working

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Set workbook name not working

I don't see the error. I'd add a "msgbox maltxt" in a few spots to make sure
the string variable was what I expected it to be.

But I'd do something like:

Private Sub Start_Click()

Dim MalWb as workbook

Set MalWb = ActiveWorkbook

Call ReskontroArk("Kunder", MalTxt)

End Sub


Private Sub ReskontroArk(ReskontroType as String, MalWb As Workbook)

'and just use that passed variable...
msgbox malwb.fullname

End Sub

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


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Set workbook name not working

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with worksheets in the same workbook ofcbill Excel Worksheet Functions 1 April 19th 08 06:16 PM
Pasting from another workbook was working and now is not Katie Excel Discussion (Misc queries) 0 October 22nd 07 04:55 PM
workbook linking cells not working within a workbook martyn Excel Discussion (Misc queries) 1 November 3rd 06 12:11 PM
Working with Workbook array Otto Moehrbach Excel Programming 3 June 15th 06 06:36 AM
Working within a workbook without activating it? hyyfte[_9_] Excel Programming 1 September 20th 04 03:34 PM


All times are GMT +1. The time now is 07:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"