ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get the value oa an optionbutton from another workbook (https://www.excelbanter.com/excel-programming/378732-how-get-value-oa-optionbutton-another-workbook.html)

George M[_2_]

How to get the value oa an optionbutton from another workbook
 
I want to get the value of the optionbutton from another workbook
without opening it and let the user choose the workbook.

It works fine when the workbook is open but when it is closed i get
runtime error 9 subscript out of range.


Sub macro1()


begin:
Dim Fname
Dim z, x, c, v As Variant


Dim N As Long
Dim pathname
Dim targetpath
Dim filename
Dim filenametf As Workbook


pathname = ActiveWorkbook.Path


use:
ChDrive [pathname]
ChDir [pathname]


Fname = Application.GetOpenFilename(filefilter:="Excel Files
(*.xls), *.xls")
MsgBox (Fname)
Set filenametf = Workbooks(Dir(Fname))


v = filenametf.Worksheets("sheet1").OptionButton1.Valu e
MsgBox (v)


end sub


Thanks for looking


Peter T

How to get the value oa an optionbutton from another workbook
 
Not possible, at least not in any conventional way. Why not Link the
optionbutton to a cell, search this ng for ways to read cell values (ie the
linked cell) in a closed workbook.

Regards,
Peter T


"George M" wrote in message
ps.com...
I want to get the value of the optionbutton from another workbook
without opening it and let the user choose the workbook.

It works fine when the workbook is open but when it is closed i get
runtime error 9 subscript out of range.


Sub macro1()


begin:
Dim Fname
Dim z, x, c, v As Variant


Dim N As Long
Dim pathname
Dim targetpath
Dim filename
Dim filenametf As Workbook


pathname = ActiveWorkbook.Path


use:
ChDrive [pathname]
ChDir [pathname]


Fname = Application.GetOpenFilename(filefilter:="Excel Files
(*.xls), *.xls")
MsgBox (Fname)
Set filenametf = Workbooks(Dir(Fname))


v = filenametf.Worksheets("sheet1").OptionButton1.Valu e
MsgBox (v)


end sub


Thanks for looking





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com