Solved

how to reference a range in an other excel file

Posted on 2015-02-06
6
37 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 500 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 48

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
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…

631 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