Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-import another xls file

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default macro-import another xls file

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-import another xls file

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!

.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default macro-import another xls file

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!

.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-import another xls file

Hi, i just want to import an xls file, but thru an macro, and after i import
the file, i will add some codes myself. I need to hit a button linked to an
macro and the macro to open an browse window. I will select the file i need,
hit ok and the excel to import in active sheet, that file. After this, the
macro will format the content, but this is another problem i will deal with
later. I only need the macro to import a file by browsing after it.

Can this be done?
Thanks!

"Dave Peterson" a scris:

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
.


--

Dave Peterson
.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default macro-import another xls file

What do you mean by "import"? The code I posted will display the file
open dialog to prompt you to select the file. Once that is complete,
you need to open the file:

Dim WB As Workbook
Set WB = Application.Workbooks.Open(Fname)

where FName is the file name selected in the Open dialog. Beyond that
you need to explain just you mean by "want to import an xls".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Thu, 1 Apr 2010 06:28:08 -0700, puiuluipui
wrote:

Hi, i just want to import an xls file, but thru an macro, and after i import
the file, i will add some codes myself. I need to hit a button linked to an
macro and the macro to open an browse window. I will select the file i need,
hit ok and the excel to import in active sheet, that file. After this, the
macro will format the content, but this is another problem i will deal with
later. I only need the macro to import a file by browsing after it.

Can this be done?
Thanks!

"Dave Peterson" a scris:

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
.


--

Dave Peterson
.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default macro-import another xls file

Opening a file does not "import" it into anything.

What portion of that opened file do you need imported to an active workbook?

That's what you need to describe.


Gord Dibben MS Excel MVP

On Thu, 1 Apr 2010 06:28:08 -0700, puiuluipui
wrote:

Hi, i just want to import an xls file, but thru an macro, and after i import
the file, i will add some codes myself. I need to hit a button linked to an
macro and the macro to open an browse window. I will select the file i need,
hit ok and the excel to import in active sheet, that file. After this, the
macro will format the content, but this is another problem i will deal with
later. I only need the macro to import a file by browsing after it.

Can this be done?
Thanks!

"Dave Peterson" a scris:

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
.


--

Dave Peterson
.


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-import another xls file

Hi, i will tell you what i tried, step by step. I'm not good at explaining,
so if i tell you what steps i've made you will understand better.
ToolsMacroRecord new macroDataImport external dataImport data and from
the browse window i selected an excel file that has been imported. This is
the code:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 01.04.2010 by puiuluipui
'

'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password=" """;User
ID=Admin;Data Source=C:\Users\puiuluipui\Desktop\Alex\excel.xls; Mode=Share
Den" _
, _
"y Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System
database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";Je" _
, _
"t OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=" _
, _
"1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Cop" _
, _
"y Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Sheet1$")
.Name = "excel"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "C:\Users\puiuluipui\Desktop\Alex\excel.xls"
.Refresh BackgroundQuery:=False
End With
End Sub


The problem is that this macro will allways open only the file named "excel".
What i need is that after i run this code, to be able to choose what file i
want.

I guess that some lines from this code must be changed. Perhaps the lines
containing the file source.

Can this code be made to let me choose everytime what file to import?
Basically to do exactly like i did in the first place when i recorded the
macro.

Can this be done?
Thanks!







"Gord Dibben" wrote:

Opening a file does not "import" it into anything.

What portion of that opened file do you need imported to an active workbook?

That's what you need to describe.


Gord Dibben MS Excel MVP

On Thu, 1 Apr 2010 06:28:08 -0700, puiuluipui
wrote:

Hi, i just want to import an xls file, but thru an macro, and after i import
the file, i will add some codes myself. I need to hit a button linked to an
macro and the macro to open an browse window. I will select the file i need,
hit ok and the excel to import in active sheet, that file. After this, the
macro will format the content, but this is another problem i will deal with
later. I only need the macro to import a file by browsing after it.

Can this be done?
Thanks!

"Dave Peterson" a scris:

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
.


--

Dave Peterson
.


.

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default macro-import another xls file

Try:

Sub Macro1()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
exit sub 'user hit cancel
end if

With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password=" """;" _
& "User ID=Admin;Data Source=" & fname & ";Mode=Share Den" _

....rest of your recorded code here.

.....

(Untested, uncompiled. Watch for typos.)

puiuluipui wrote:

Hi, i will tell you what i tried, step by step. I'm not good at explaining,
so if i tell you what steps i've made you will understand better.
ToolsMacroRecord new macroDataImport external dataImport data and from
the browse window i selected an excel file that has been imported. This is
the code:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 01.04.2010 by puiuluipui
'

'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password=" """;User
ID=Admin;Data Source=C:\Users\puiuluipui\Desktop\Alex\excel.xls; Mode=Share
Den" _
, _
"y Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System
database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";Je" _
, _
"t OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=" _
, _
"1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Cop" _
, _
"y Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Sheet1$")
.Name = "excel"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "C:\Users\puiuluipui\Desktop\Alex\excel.xls"
.Refresh BackgroundQuery:=False
End With
End Sub

The problem is that this macro will allways open only the file named "excel".
What i need is that after i run this code, to be able to choose what file i
want.

I guess that some lines from this code must be changed. Perhaps the lines
containing the file source.

Can this code be made to let me choose everytime what file to import?
Basically to do exactly like i did in the first place when i recorded the
macro.

Can this be done?
Thanks!

"Gord Dibben" wrote:

Opening a file does not "import" it into anything.

What portion of that opened file do you need imported to an active workbook?

That's what you need to describe.


Gord Dibben MS Excel MVP

On Thu, 1 Apr 2010 06:28:08 -0700, puiuluipui
wrote:

Hi, i just want to import an xls file, but thru an macro, and after i import
the file, i will add some codes myself. I need to hit a button linked to an
macro and the macro to open an browse window. I will select the file i need,
hit ok and the excel to import in active sheet, that file. After this, the
macro will format the content, but this is another problem i will deal with
later. I only need the macro to import a file by browsing after it.

Can this be done?
Thanks!

"Dave Peterson" a scris:

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
.


--

Dave Peterson
.


.


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro-import another xls file

It works great!
Thanks!

"Dave Peterson" wrote:

Try:

Sub Macro1()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
exit sub 'user hit cancel
end if

With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password=" """;" _
& "User ID=Admin;Data Source=" & fname & ";Mode=Share Den" _

....rest of your recorded code here.

.....

(Untested, uncompiled. Watch for typos.)

puiuluipui wrote:

Hi, i will tell you what i tried, step by step. I'm not good at explaining,
so if i tell you what steps i've made you will understand better.
ToolsMacroRecord new macroDataImport external dataImport data and from
the browse window i selected an excel file that has been imported. This is
the code:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 01.04.2010 by puiuluipui
'

'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password=" """;User
ID=Admin;Data Source=C:\Users\puiuluipui\Desktop\Alex\excel.xls; Mode=Share
Den" _
, _
"y Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System
database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";Je" _
, _
"t OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=" _
, _
"1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Cop" _
, _
"y Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Sheet1$")
.Name = "excel"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "C:\Users\puiuluipui\Desktop\Alex\excel.xls"
.Refresh BackgroundQuery:=False
End With
End Sub

The problem is that this macro will allways open only the file named "excel".
What i need is that after i run this code, to be able to choose what file i
want.

I guess that some lines from this code must be changed. Perhaps the lines
containing the file source.

Can this code be made to let me choose everytime what file to import?
Basically to do exactly like i did in the first place when i recorded the
macro.

Can this be done?
Thanks!

"Gord Dibben" wrote:

Opening a file does not "import" it into anything.

What portion of that opened file do you need imported to an active workbook?

That's what you need to describe.


Gord Dibben MS Excel MVP

On Thu, 1 Apr 2010 06:28:08 -0700, puiuluipui
wrote:

Hi, i just want to import an xls file, but thru an macro, and after i import
the file, i will add some codes myself. I need to hit a button linked to an
macro and the macro to open an browse window. I will select the file i need,
hit ok and the excel to import in active sheet, that file. After this, the
macro will format the content, but this is another problem i will deal with
later. I only need the macro to import a file by browsing after it.

Can this be done?
Thanks!

"Dave Peterson" a scris:

Chip's code shows you how to get the name of the file from the user. It doesn't
do the actual import.

You'll have to add that portion yourself -- or explain what you're doing in
greater detail.


puiuluipui wrote:

Hi, i have some problems.
The code run corectly and browse for whatever file i need, but when i click
that file, it doesn;t import anything!
What am i doing wrong? I have excel 2003.
Thanks!

"Chip Pearson" a scris:

Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim Filter As String
' Excel 2003 workbooks
Filter = "Excel Files (*.xls),*.xls"
' Excel 2007 workbooks workbooks
Filter = "Excel Files (*.xlsx;*.xlsm;*.xlsb),*.xlsx;*.xlsm;*.xlsb"
' Excel 2003 and 2007
Filter = "Excel Files
(*.xls;*.xlsx;*.xlsm;*.xlsb),*.xls;*.xlsx;*.xlsm;* .xlsb"

FName = Application.GetOpenFilename(filefilter:=Filter)
If FName = False Then
Debug.Print "cancel"
Else
Debug.Print "selected: " & FName
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Wed, 31 Mar 2010 14:00:01 -0700, puiuluipui
wrote:

Hi, i need a macro to import another xls file.When i run macro i need a
window to appear and to browse to the file i need to import. I allways open
another file, so i want to browse for the file.
Can this be done?
Thanks!
.


--

Dave Peterson
.


.


--

Dave Peterson
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
import file so that it is a actual csv file, no excel cell version broncoburt New Users to Excel 1 November 21st 09 09:09 PM
import data from txt file to an existing excel file shaji Excel Discussion (Misc queries) 1 September 12th 09 04:15 PM
Skipping Import Text File dialog in a Macro Leon Excel Discussion (Misc queries) 5 January 21st 08 09:12 PM
How come I can't import an .svc file(Open Office) to Excel file? beezer Excel Discussion (Misc queries) 1 August 28th 06 12:05 AM
Would Like to Automate Batch File Creation and Text FIle Import socrtwo Excel Discussion (Misc queries) 2 August 18th 06 03:54 PM


All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"