×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Linking VB TO EXCEL
2

Linking VB TO EXCEL

Linking VB TO EXCEL

(OP)
I just started using visual basic and I want to know how to link Excel with visual basic. I created the interface already...I jus need help wit the coding.

RE: Linking VB TO EXCEL

Usually you transfer data from excel spreadsheet into VB and values you get in VB variables back into excel spreadsheet- somewhere you have to start.
M777182

RE: Linking VB TO EXCEL

The easy way is to use GetObject or CreateObject (depends if Excel is already running or not). To open, Dim myXL at form or global level as required then use something like:

CODE

On Error Resume Next 'ignore errors
 Set myXL = GetObject(, "Excel.Application") 'look for a running copy
 If Err.Number <> 0 Then 'If Excel is not running then
  Set myXL = CreateObject("Excel.Application") 'run it
 End If
 Err.Clear   ' Clear Err object in case error occurred.
 On Error GoTo 0 'Resume normal error processing
 myXL.Workbooks.Open ("c:\j3.xls") ' Your full path
 myXL.Visible = True ' or False if you're just processing
 myXL.Worksheets(1).Range("J1").Value = "fred" 'set value
 lngInput = myXL.Worksheets(1).Range("H2").Value ' get

To close when you're finished:

CODE

Dim W As Workbook
  For Each W In Workbooks
    W.Close savechanges:=False ' or True as reqd
  Next W
myXL.Quit
Set myXL = Nothing

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

UK steam enthusiasts: www.essexsteam.co.uk

RE: Linking VB TO EXCEL

(OP)
Thanks 4 the help..i'll give it a try

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources