Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to reference a range in an other excel file

Posted on 2015-02-06
6
Medium Priority
?
39 Views
Last Modified: 2016-02-12
I have a function I need to call from an outside excel spreadsheet
so the code I have is

 
Sub CleanAll()
    Dim rng As Range

    For Each rng In Sheets("Sheet1").Range("A1:K1500").Cells 'adjust sheetname and range accordingly
        rng.Value = AlphaNumericOnly(rng.Value)
    Next
End Sub

Open in new window


is it possible to reference sheet1 in file "c:\temp\myexcelfile.xls"

thanks in advance
0
Comment
Question by:damixa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 2000 total points
ID: 40594781
This works if you want to open and update the target workbook.

Sub CleanAll()
    Dim wb as workbook
    Dim rng As Range
Set wb = Application.Workbooks.Open ("c:\temp\myexcelfile.xls")
with wb
    For Each rng In .Sheets("Sheet1").Range("A1:K1500").Cells 'adjust sheetname and range accordingly
        rng.Value = AlphaNumericOnly(rng.Value)
    Next
end with
End Sub

Open in new window

0
 

Author Comment

by:damixa
ID: 40594790
Do you know if I can do this if I am in access? so run this code from an access application?

thanks
0
 
LVL 18

Expert Comment

by:Simon
ID: 40594802
Yes, from Access you'd have to create an object reference to the Excel application. If you add a reference to Excel from the Access VBE using Tools/References you can still use intellisense. I can't test this from where I'm sitting, so the code below may need minor tweaks...

e.g.
Sub CleanAll()
dim objExcel as excel.application
   Dim wb as excel.workbook
    Dim rng As excel.Range
set objExcel= CreateObject("Excel.Application")
Set wb = objExcel.Workbooks.Open ("c:\temp\myexcelfile.xls")
with wb
    For Each rng In .Sheets("Sheet1").Range("A1:K1500").Cells 'adjust sheetname and range accordingly
        rng.Value = AlphaNumericOnly(rng.Value)
    Next
end with
End Sub

Open in new window

0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40640130
I've requested that this question be closed as follows:

Accepted answer: 500 points for SimonAdept's comment #a40594802

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:damixa
ID: 40640129
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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…

705 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