Solved

Reference a Defined Name in VBA in an Excel AddIn

Posted on 2015-01-08
5
141 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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