Solved

Reference a Defined Name in VBA in an Excel AddIn

Posted on 2015-01-08
5
135 Views
Last Modified: 2015-01-08
I have added a Defined Name called "ConnectionString" on "Sheet1" in an Excel AddIn I have written.  What is the proper way to reference that Defined Name within the VBA of the AddIn itself?

ActiveWorkbook.Range("ConnectionString").Value   and   ThisWorkBook.Range("ConnectionString").Value
are not correct because they will look for the defined name in the file the user is working with and not the AddIn workbook.   I want to reference the name inside the VBA of the AddIn.

Thanks,
Jerry
0
Comment
Question by:Jerry Paladino
5 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 40539122
when you reach Sheet1 in VBA of the Addin
Dim WS as worksheet
set WS = sheets("Sheet1")
WS.Range("ConnectionString").Value  .... should reference what you want.

gowflow
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40539140
I believe you'll need to activate the Add-In file in order to retrieve the defined name.  For example:

Sub ProcessIt()
    Dim strActiveWB as String

    strActiveWB = ActiveWorkbook.Name

    Application.Workbooks("addinname").Activate 'replace with actual filename in quotes including extension - xlam
    strCS = Sheets("Sheet1").Range("ConnectionString").Value

.
.
    Application.Workbooks(strActiveWB).Activate

End Sub

Open in new window


Regards,
-Glenn
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40539141
or I should rather say

ActiveWorkbook.Sheets("Sheet1").Range("ConnectionString").Value

gowflow
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 40539327
You can get the value of a range in a worksheet of the Add-In in the same way you would any other workbook....

    Workbooks("AddInName.xlam").Worksheets("Sheet1").Range("ConnectionString").Value
0
 
LVL 16

Author Closing Comment

by:Jerry Paladino
ID: 40539412
Wayne,

Thank you...   Yes, this works well for what I am trying to accomplish.   A nice plus is that since the AddIn is already loaded I can reference the AddInName without hard coding the path or using Application.UserLibraryPath to get the path.  Much appreciated.

gowflow & Glenn - thank you both for your suggestions.

Thanks,
Jerry
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now