|
-
Mar 29th, 2007, 03:43 AM
#1
Thread Starter
Hyperactive Member
Excel to Access using VBA MS access
Hi,
Can anyone help me how to export specific excel file with only selected column to a specific table in MS access?
I can do that using VBA ms excel but i want to try it in MS Access VBA code.
The step is selecting 1st the ms Access database to be updated and then to follow selecting MS excel file that will be the source of data.
Thanks!
"Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"
-
Mar 29th, 2007, 03:44 AM
#2
Re: Excel to Access using VBA MS access
How about using Access to import the range?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 29th, 2007, 06:11 AM
#3
Thread Starter
Hyperactive Member
Re: Excel to Access using VBA MS access
Can...
All I want is to move data form excel to specific MS access table.
Meaning there is diff MS access tool (VBA) in between the 2 (MS excel and MS access)
"Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"
-
Mar 29th, 2007, 03:24 PM
#4
Re: Excel to Access using VBA MS access
Ok, lets restart here.
Where do you need to execute (button click or whatever) the transfer from?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 29th, 2007, 04:05 PM
#5
Re: Excel to Access using VBA MS access
Hi Ash
What I could gather from your post is that you are having trouble opening the relevant Excel File and then getting the relevant values from that file to store in the access table...
If I have understood you correctly then this should help...
Paste this code in the click event of a commanbutton say(cmd1)
I am not writing the code to update the table as I am assuming that you know how to do that...
vb Code:
Option Compare Database
Private Sub cmd1_Click()
'Opening Excel From Access
Dim oXLApp As Excel.Application
'Declare the object variables
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
Set oXLApp = New Excel.Application
'Open the relevant Excel File
'Replace it with your file name
Set oXLBook = oXLApp.workbooks.Open("C:\Temp\myfile.xls")
oXLApp.Visible = True
'Show it to the user
'Comment the above if you don't want the user to see the Excel File
'****************** updating the Table ***********************
'********** From Excel file, Say from Cell C1:C10 ************
For i = 1 To 10 'Change 10 to the relevant row number
'Update the relevant table field using a loop by storing the
'Range("C" & i).Value
Next i
MsgBox "Table Updated"
Set oXLSheet = Nothing
'Disconnect from all Excel objects
Set oXLBook = Nothing
Set oXLApp = Nothing
End Sub
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 29th, 2007, 04:19 PM
#6
Re: Excel to Access using VBA MS access
Koolsid, that code is to be executed from within Access. I dont think that will be what the poster wants.
The step is selecting 1st the ms Access database to be updated and then to follow selecting MS excel file that will be the source of data.
Which is why I havent written any code yet.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 29th, 2007, 04:28 PM
#7
Re: Excel to Access using VBA MS access
I can do that using VBA ms excel but i want to try it in MS Access VBA code.
The step is selecting 1st the ms Access database to be updated and then to follow selecting MS excel file that will be the source of data.
Hi Rob
What I understood from the quote is that : From within Access, he wants to access the table and then access the Excel File to pull the data...
I might be wrong...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 29th, 2007, 04:39 PM
#8
Re: Excel to Access using VBA MS access
Yes, but what threw me off was "The step is selecting 1st the ms Access database to be updated ..."
Maybe doing it in some other environment or selecting another access db from within an access db or ???
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2007, 01:01 AM
#9
Thread Starter
Hyperactive Member
Re: Excel to Access using VBA MS access
I will not make it very confusing. Actually I have 3 files as follows:
1) MS Access Database (where all the data from excel be transferred here)
2) Multiple excel file ( I have raw data from excel, different workbooks, and the data will be moved to each table inside MS access Database)
3) MS Access Tool : ( this is the one containing a code to update the MS Access database by selecting MS Access database to be updated and then one select multiple excel file workbook. Inside the code I will chooses the file name of each excel file so that I can move the data inside each table inside MS access database)
I hope it not make everybody confused on this. My apology if this not that clear on my first post...... You see i just want to create a database with many tables that contain data's from ms excel.... All the data I have is in MS excel and I just want to put it inside the database... I can do it in MS excel like this:
VBA excel:
Set rS = db.OpenRecordset("RECORD_NAME", dbOpenTable)
On Error Resume Next
r = 6
Do While Len(Range("A" & r).Formula) > 0
With rS
.AddNew
'.Fields("Date") = Range("A" & r).Value
'.Fields("PLMN name") = Range("B" & r).Value
.Fields("Date") = Range("A" & r).Value
.Fields("name") = Range("B" & r).Value
.Fields("Surname") = Range("C" & r).Value
.update
End With
r = r + 1 ' next row
Loop
rS.Close
Set rS = Nothing
db.Close
Set db = Nothing
You see I can select specific column in MS excel and move it to specific column in a specific table.... My problem now is I want to migrate the code inside no.3 (MS Access Tool). Now everybody is wondering why I need to select a specific database.. The reason is we just need the tool to update it. And after 1 month data, I will discharge this database and create a new one again... So i dont want to create a code inside this database since after a month a new one is needed... It will just serve as a storage of data (like swl server) and then there is another tool I have to process all the raw data in this MS Access database.
Thank a lot for your concern.... Hope you all can help me with this...Best regards...
Last edited by Asher David; Mar 31st, 2007 at 01:03 AM.
Reason: wrong grammar
"Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"
-
Mar 31st, 2007, 01:04 AM
#10
Re: Excel to Access using VBA MS access
See this FAQ thread for the built in function in Access for importing a Excel spreadsheet.
http://vbforums.com/showthread.php?t=402075
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 3rd, 2007, 12:04 PM
#11
Junior Member
Re: Excel to Access using VBA MS access
Hey Kool,
I get a compile error from the very 1st line
Dim oXLApp As Excel.Application
Its says "User-defined type not defined"
Is there some switch or something that needs to be set for this work?
<>Sulabh
-
Apr 3rd, 2007, 12:55 PM
#12
Re: Excel to Access using VBA MS access
Welcome to the Forums.
You need to add a reference to Excel xx.0 Object Library
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 4th, 2007, 11:46 AM
#13
Junior Member
Re: Excel to Access using VBA MS access
Thanks for the welcome,
but I still have this issue so I looked at your example "Excel 2003 And Early Binding Automation Code Example"
Copied and pasted it. Does that code work for VBA in access? cause thats what im using. So anyway I get the error it just moved from the sub command button to the sub form load when i double click the form. What up... I don't know man... is there some other step im missing?
-
Apr 4th, 2007, 01:25 PM
#14
Re: Excel to Access using VBA MS access
It only deals with Excel so adding the Reference via the menu in the VBA IDE behind the form is all that is required.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2007, 09:20 AM
#15
Junior Member
Re: Excel to Access using VBA MS access
 Originally Posted by RobDog888
It only deals with Excel so adding the Reference via the menu in the VBA IDE behind the form is all that is required.
In the VBA code screen go to Tools -> References ->Click Microsoft Excel 12.0 Object Library. Done.
I figured it out thanks.
<>Sulabh
Last edited by SulPal; Apr 5th, 2007 at 10:48 AM.
-
Apr 16th, 2007, 04:11 AM
#16
Thread Starter
Hyperactive Member
Re: Excel to Access using VBA MS access
Hi Robb,
But does this code cannot select the column I want to copy (specific column). You see let say I have 20 columns with data's but I want to copy the specific column only.
I tried this one but it seems it can copy all the excel sheets but not specific cell.
Thanks!
Last edited by Asher David; Apr 19th, 2007 at 05:45 AM.
"Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"
-
May 28th, 2007, 03:52 AM
#17
Thread Starter
Hyperactive Member
Re: Excel to Access using VBA MS access
anymore help about by previous query?
Thanks!
"Its easy to teach FAITHFUL MAN to be ABLE than ABLE MAN to be FAITHFUL"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|