Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Inputbox to return range from another workbook

hi,

i want the user to open an excel workbook of his choice and then
choose a range from that excel workbook.

this, of course, has to happen during the macro run.
and the macro needs to capture the name of the new workbook, the sheet
name and range chosen.

when using inputbox, it works when i choose a range within the same
workbook as is the macro.
but when i try it with another workbook - nothing is returned.

any ideas?

I am using the code that I found on one of the pages on this very
forum...

Sub tester1()


On Error Resume Next

Set rng = Nothing
Set rng = Application.InputBox("Select a cell with the mouse",
Type:=8)
MsgBox rng.Address
rng.Parent.Activate
If Not rng Is Nothing Then
rng(1).Select
Else
MsgBox "You didn't select"
End If


End Sub


Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Inputbox to return range from another workbook

Try this:

Sub test()
Dim fName As String, wb As Workbook
Dim rng As Range

fName = Application.GetOpenFilename()
If fName < "False" Then
Set wb = Workbooks.Open(fName)
Else
Exit Sub
End If
Set rng = Application.InputBox("Select a cell", Type:=8)

MsgBox "Range: " & rng.Address & vbLf & _
"Filename: " & wb.Name & vbLf & _
"Sheet: " & ActiveSheet.Name
wb.Close SaveChanges:=False
End Sub

--
Dan


On Dec 18, 9:27 am, wrote:
hi,

i want the user to open an excel workbook of his choice and then
choose a range from that excel workbook.

this, of course, has to happen during the macro run.
and the macro needs to capture the name of the new workbook, the sheet
name and range chosen.

when using inputbox, it works when i choose a range within the same
workbook as is the macro.
but when i try it with another workbook - nothing is returned.

any ideas?

I am using the code that I found on one of the pages on this very
forum...

Sub tester1()

On Error Resume Next

Set rng = Nothing
Set rng = Application.InputBox("Select a cell with the mouse",
Type:=8)
MsgBox rng.Address
rng.Parent.Activate
If Not rng Is Nothing Then
rng(1).Select
Else
MsgBox "You didn't select"
End If

End Sub

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Inputbox to return range from another workbook

Forgot a couple things... try this one:

Sub test()
Dim fName As String, wb As Workbook
Dim rng As Range
fName = Application.GetOpenFilename()
If fName < "False" Then
Set wb = Workbooks.Open(fName)
Else
Exit Sub
End If
Set rng = Application.InputBox("Select a cell", Type:=8)
If Not rng Is Nothing Then
rng.Parent.Activate
MsgBox "Range: " & rng.Address & vbLf & _
"Filename: " & wb.Name & vbLf & _
"Sheet: " & ActiveSheet.Name
Else
MsgBox "Nothing selected!"
End If
wb.Close SaveChanges:=False
End Sub

--
Dan

On Dec 18, 9:27 am, wrote:
hi,

i want the user to open an excel workbook of his choice and then
choose a range from that excel workbook.

this, of course, has to happen during the macro run.
and the macro needs to capture the name of the new workbook, the sheet
name and range chosen.

when using inputbox, it works when i choose a range within the same
workbook as is the macro.
but when i try it with another workbook - nothing is returned.

any ideas?

I am using the code that I found on one of the pages on this very
forum...

Sub tester1()

On Error Resume Next

Set rng = Nothing
Set rng = Application.InputBox("Select a cell with the mouse",
Type:=8)
MsgBox rng.Address
rng.Parent.Activate
If Not rng Is Nothing Then
rng(1).Select
Else
MsgBox "You didn't select"
End If

End Sub

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Inputbox to return range from another workbook

Hi Dan,

many thx.
Your code works great.

There was just one complication.
For a very specific Excel file - it gives me the error "Run-time error
'13' Type mismatch"

It halts at "Set wb = Workbooks.Open(fName)"

The code works with all other excel files.

Could there be any reasons that you could think of - as to why this
specific excel file gives such an error?

Thanks anyways
Saju


On Dec 18, 5:06 pm, "Dan R." wrote:
Forgot a couple things... try this one:

Sub test()
Dim fName As String, wb As Workbook
Dim rng As Range
fName = Application.GetOpenFilename()
If fName < "False" Then
Set wb = Workbooks.Open(fName)
Else
Exit Sub
End If
Set rng = Application.InputBox("Select a cell", Type:=8)
If Not rng Is Nothing Then
rng.Parent.Activate
MsgBox "Range: " & rng.Address & vbLf & _
"Filename: " & wb.Name & vbLf & _
"Sheet: " & ActiveSheet.Name
Else
MsgBox "Nothing selected!"
End If
wb.Close SaveChanges:=False
End Sub

--
Dan

On Dec 18, 9:27 am, wrote:



hi,


i want the user to open an excel workbook of his choice and then
choose a range from that excel workbook.


this, of course, has to happen during the macro run.
and the macro needs to capture the name of the new workbook, the sheet
name and range chosen.


when using inputbox, it works when i choose a range within the same
workbook as is the macro.
but when i try it with another workbook - nothing is returned.


any ideas?


I am using the code that I found on one of the pages on this very
forum...


Sub tester1()


On Error Resume Next


Set rng = Nothing
Set rng = Application.InputBox("Select a cell with the mouse",
Type:=8)
MsgBox rng.Address
rng.Parent.Activate
If Not rng Is Nothing Then
rng(1).Select
Else
MsgBox "You didn't select"
End If


End Sub


Thanks- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Inputbox to return range from another workbook

Saju,

Just add 'On Error Resume Next' to the top of your code under the dim
statements and that should clear it up.

--
Dan

On Dec 19, 5:48 am, wrote:
Hi Dan,

many thx.
Your code works great.

There was just one complication.
For a very specific Excel file - it gives me the error "Run-time error
'13' Type mismatch"

It halts at "Set wb = Workbooks.Open(fName)"

The code works with all other excel files.

Could there be any reasons that you could think of - as to why this
specific excel file gives such an error?

Thanks anyways
Saju

On Dec 18, 5:06 pm, "Dan R." wrote:



Forgot a couple things... try this one:


Sub test()
Dim fName As String, wb As Workbook
Dim rng As Range
fName = Application.GetOpenFilename()
If fName < "False" Then
Set wb = Workbooks.Open(fName)
Else
Exit Sub
End If
Set rng = Application.InputBox("Select a cell", Type:=8)
If Not rng Is Nothing Then
rng.Parent.Activate
MsgBox "Range: " & rng.Address & vbLf & _
"Filename: " & wb.Name & vbLf & _
"Sheet: " & ActiveSheet.Name
Else
MsgBox "Nothing selected!"
End If
wb.Close SaveChanges:=False
End Sub


--
Dan


On Dec 18, 9:27 am, wrote:


hi,


i want the user to open an excel workbook of his choice and then
choose a range from that excel workbook.


this, of course, has to happen during the macro run.
and the macro needs to capture the name of the new workbook, the sheet
name and range chosen.


when using inputbox, it works when i choose a range within the same
workbook as is the macro.
but when i try it with another workbook - nothing is returned.


any ideas?


I am using the code that I found on one of the pages on this very
forum...


Sub tester1()


On Error Resume Next


Set rng = Nothing
Set rng = Application.InputBox("Select a cell with the mouse",
Type:=8)
MsgBox rng.Address
rng.Parent.Activate
If Not rng Is Nothing Then
rng(1).Select
Else
MsgBox "You didn't select"
End If


End Sub


Thanks- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -

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
InputBox that obtains Workbook, Worksheet, and Range J@Y Excel Programming 4 April 10th 07 02:36 PM
Application.inputbox for another workbook Utkarsh Excel Programming 2 September 8th 06 05:57 PM
Trying to return Range from InputBox Jiana Excel Programming 3 April 28th 04 11:25 PM
Inputbox used to return value of selected cell D.S.[_2_] Excel Programming 5 October 25th 03 06:53 PM
Inputbox to return address of cell selected by mouse D.S.[_2_] Excel Programming 2 October 25th 03 06:48 PM


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