Help with VBA script for Excel
"programmernovice" wrote in message
On Thursday, December 19, 2019 at 1:38:47 PM UTC-6, Peter T wrote:
"programmernovice" wrote in message
I'm trying to write a script to navigate to the Solver check-box under
References in the Editor. So far I have:
application.sendkeys (%)
application.sendkeys (L)
application.sendkeys (V)
That gets to the VBA Editor.
I cannot figure out how to code the next steps:
Click on "Tools"
Click on "References"
Click in the Solver box.
Any help or suggestion would be appreciated.
I assume you're trying to add a Solver reference to your file..
Dim ref As Object ' Reference
Dim vbp As Object ' VBProject
Dim ad As AddIn
Set vbp = ThisWorkbook.VBProject
On Error Resume Next
Set ref = vbp.References("Solver")
If ref Is Nothing Then
Set ad = Application.AddIns("Solver Add-in")
Set ref = vbp.References.AddFromFile(ad.FullName)
End If
If this for distributing would need more than just this.
Requires trust access to the VBA Project in security settings.
Peter T
Thanks Peter. Purpose is, indeed, to add Solver reference. Is your code
to be added to what I started with, or it's the whole thing? I appreciate
it.
Your SendKeys wouldn't work, but no point trying to correct as at best
SendKeys is flakey and only for use as a last resort. Instead, with some
caveats, you can add and remove references with code, also just about
everything relating to a VBA-project. So bin the SendKeys and yes - 'it's
the whole thing'!
Or rather, it's the base essentials and might need more work, hence my
comment re if distributing.
Peter T
|