Results 1 to 4 of 4

Thread: implement VB on Excel

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    92

    Exclamation

    hi !

    i want to know where i can find information for implemt VB on Excel .

    for example :

    1. how i connect to the excel file ?
    2.how i import the data ?
    3.write to the Excel .
    4.refer to specific sheet in the *.xls file .
    .
    .
    ......

    I know how to work with SQl but in this issue i need to work with excel .

    so if ytou know on any site ,place ,articals please let me know .

    regards ,

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Look for 'Office Automation' on the Microsoft Web site. Sorry I don't have the exact URL.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Talking Macro hints

    At least for the interacting with excel part....

    if you need to figure out how to do something in excel using vb (like centering text or selecting a cell/range etc...) Try recording a macro. Then view the macro. It is not the cleanest way but in most cases you can trim off the extra 'Crap' and use the code you need. I must say though, sometimes this gets frustrating! and as another hint. Whne you come across something like this:

    selection.horizontalalignment = xlCenter

    the xlCenter (or whatever) has a numeric value. Use the object browser and search for the word. select it, then look at the bottom. The number is displayed.

    Using these techniques I was able to make a program that opens a text file....reads all the data in it....sorts it...then dumps it into an excel workbook (containing about 20 sheets) and even make it create charts with specific line color and thickness! I impressed myself!

    Good Luck!!

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Junior Member
    Join Date
    Oct 2000
    Posts
    18
    Here are the basic commands to get you started. You will need to add the Excel Object library to your project's references.
    Code:
    Dim ws As Worksheet
    Dim sVal As String
    
    Workbooks.Open FileName:="C:\YourFile.xls"
    Workbooks.Application.Visible = True
    Set ws = ActiveWorkbook.Sheets("Sheet1")
    'Get current data from A1
    sVal = ws.Range("A1").Text
    'Enter new data in A1
    ws.Range("A1").FormulaR1C1 = "ABCD"
    'Save the file and close Excel
    Workbooks.Application.ActiveWorkbook.Save
    Workbooks.Application.Quit
    Workbooks.Application.DisplayAlerts = False
    Hope this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width