Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default How to refer to a workbook?

I usually need to refer to other books during a macro. Lets consider a simple
sample as follows:

Sub SpclMcro()
Dim SrcWS As Worksheet
Dim DstWS As Worksheet
Dim SrcWB As Workbook
Dim Dst As Workbook
Dim Src As Range, Dest As Range
Set Src = Application.InputBox("WHAT?", , , , , , , 8)
Set Dest = Application.InputBox("WHERE?", , , , , , , 8)
MsgBox Src.Workbook.Name
Src.Copy Dest
End Sub

How can I get the name of the workbook of a cell/range as in:

MsgBox Src.Workbook.Name

Furthermore how to select a destination in ANY other workbook because during
the inputbox display of:

Set Dest = Application.InputBox("WHERE?", , , , , , , 8)

the workbook selection mode is inactive?

--
Thanx in advance,
Best Regards,

Faraz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to refer to a workbook?


You use the property Parent

The parent of range on a worksheet is the sheet.
The parent of a sheet is the workbook

Set Src = Application.InputBox("WHAT?", , , , , , , 8)
SheetName = Src.parent.name
BookName = Src.parent.parent.name


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=166368

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default How to refer to a workbook?

Hi Faraz,

Hope you can follow my example. I tried to break it up so it will make more
sense.

Sub SpclMcro()
Dim SrcWS As Worksheet
Dim DstWS As Worksheet
Dim SrcWB As Workbook
Dim Dst As Workbook
Dim Src As Range
Dim Dest As Range

Set Src = Application.InputBox("WHAT?", , , , , , , 8)
'Set Dest = Application.InputBox("WHERE?", , , , , , , 8)

'Set Src = ActiveSheet.Range("A1:A10")

'Worksheet of range Src
Set SrcWS = Src.Parent
MsgBox SrcWS.Name

'Workbook of worksheet SrcWS
Set SrcWB = SrcWS.Parent
MsgBox SrcWB.Name

'Therefore in one line the workbook of range Src
Set SrcWB = Src.Parent.Parent
MsgBox SrcWB.Name

End Sub


--
Regards,

OssieMac


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default How to refer to a workbook?

The following commented out line was just used during testing. Please ignore
it. Also no doubt you will work out what you need for Dest.

'Set Src = ActiveSheet.Range("A1:A10")

--
Regards,

OssieMac


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default How to refer to a workbook?

Hi yet again Faraz,

Finally worked out an answer to your second question.
"how to select a destination in ANY other workbook because during
the inputbox display the workbook selection mode is inactive?"

You can use the Windows menu to change the workbook selection.
In xl2007 select View Ribbon, Windows block, Switch windows.
In earlier versions select Menu item Window and select required window.

--
Regards,

OssieMac


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
How to refer to a cell from another workbook in VBA diepvic Excel Programming 4 June 24th 09 09:52 AM
How to Refer to Another Excel Workbook hon123456 Excel Programming 1 January 4th 08 09:33 AM
Refer to workbook Arne Hegefors Excel Programming 1 November 15th 07 09:20 AM
Refer to more than one worksheet in a workbook Göran M Excel Worksheet Functions 0 January 2nd 06 07:02 AM
how to I refer to current workbook without using its name? confused Excel Worksheet Functions 2 June 16th 05 11:50 PM


All times are GMT +1. The time now is 06:03 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"