ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Improve 'Windows(workbook.xls).Activate" statement (https://www.excelbanter.com/excel-programming/360323-improve-windows-workbook-xls-activate-statement.html)

Hank[_6_]

Improve 'Windows(workbook.xls).Activate" statement
 

Hello,

I have a VBA routine that creates an xy data plot on worksheet (A) and
displays a regression fit in the chart textbox. I need to have the
chart drawn to force visual inspection of the data, and would like to
be able to copy the regression text that is displayed in the text box
on the on the chart to a cell on a new worksheet (B) in the same
workbook. The routine needs to be generic so that the code will run on
any workbook. Using the macro recorder, I get the code below. The
problem, for me, is to make the "Windows("Workbook1.xls").Activate"
statement generic. Using statements such as(Windows("0").Activate have
produced strange, and unpredicatebe results.

Thanks for any suggestions!

Hank

Sub Copy_Text()
'
' '
Sheets("A").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Trendlines(1).Data Label.Select
ActiveWindow.Visible = False
Windows("Workbook1.xls").Activate
Sheets("B").Select
Range("A1").Select
ActiveSheet.Paste
End Sub


--
Hank
------------------------------------------------------------------------
Hank's Profile: http://www.excelforum.com/member.php...o&userid=34042
View this thread: http://www.excelforum.com/showthread...hreadid=538047


MattShoreson[_102_]

Improve 'Windows(workbook.xls).Activate" statement
 

You try creating an excel addin (xla) which can be incorportated as part
of an excel instance.

Then you can run the macro using the reference 'activeworkbook '.

it's a little more complicated but there's plenty of information about
creating them on excelforum.com


--
MattShoreson
------------------------------------------------------------------------
MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472
View this thread: http://www.excelforum.com/showthread...hreadid=538047



All times are GMT +1. The time now is 04:33 AM.

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