265 pts.
Q:
Export or Import data Excle to Excel (VBA coding)
Hi Experts
Pls
How to possible Export or Import data Excle to Excel (VBA coding)

Ananda Debnath
ASKED: Apr 6 2009  12:15 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
1395 pts.
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • Bookmark and Share
If you want to achieve this by VBA then there are plenty of option. However, I am trying to describe the cheapest solution here. Please follow the steps below
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/9/2009 by sarfaah

Dim str As String
'This line is added by me Sarfaraz
str = InputBox("Enter the file path")


'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" _
& str & _
";Mode=Share Deny Write;Extend" _
, _
"ed Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet 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:Ne" _
, _
"w Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Co" _
, _
"mpact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Sheet1$")
.Name = "TED Month End Reports"
.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 = "D:\TED Month End Reports.xls"
.Refresh BackgroundQuery:=False
End With
End Sub

The above code will be able to take care of your issue. I have added str variable which will ask you to enter the path of MS Excel file.

Regards,
Sarfaraz Ahmed
MS Excel help
Last Answered: Apr 9 2009  8:09 AM GMT by Findsarfaraz   1395 pts.
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _