[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

vba in excel

Posted on 2004-10-20
10
Medium Priority
?
153 Views
Last Modified: 2010-05-02
good greetings!

using visual basic for application in excel. how can i retrive and insert values from/to cell?

and how can i trigger a print.

thanks your help is greatly appreciated.
JackOfPH
0
Comment
Question by:JackOfPH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12365344
Try include the M$ Excel Object Library from the References, basically the syntax is same either in VB or VBA.
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 400 total points
ID: 12365351
This is an example to Print Excel Document:

Private Sub Command6_Click()
   
    Dim excel As excel.Application
    Dim wb As Workbook
    Dim ws As Worksheet
   
    Dim tmp As String
   
    tmp = "c:\test.xls"
   
    If tmp = "" Then Exit Sub
   
    Set excel = CreateObject("Excel.Application")
   
    'excel.Visible = True
   
    Set wb = excel.Workbooks.Open(tmp)
   
    Set ws = wb.Worksheets(1)
   
    ws.PrintOut
   
    Set ws = Nothing
    wb.Close
    Set wb = Nothing
    excel.Quit
    Set excel = Nothing
   
End Sub
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12365355
to Preview it, just change line:

ws.PrintOut

to:

ws.PrintPreview
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12365381
Here comes an example to read/write an Excel document:

Private Sub Command5_Click()
    Dim excel As excel.Application
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim tmp As String
   
    tmp = "c:\test.xls"

    Set excel = CreateObject("Excel.Application")
    excel.Visible = True
   
    Set wb = excel.Workbooks.Open(tmp)
   
    Set ws = wb.Worksheets("Sheet1")
   
    i = 2
    msgbox ws.Cells(i, 3)
   ws.Cells(i, 3) = "hello world, now is " & now()
        msgbox ws.Cells(i, 3)

    wb.Save
   
    Set ws = Nothing
    wb.Close
    Set wb = Nothing
    excel.Quit
    Set excel = Nothing

    MsgBox "Done!"

End Sub
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 12377946
ryancys

it's been a while!

yuor code works! thanks but still I have a little a problem left.
how can I exclude a certain Cell from printing. lets say cell(13,5)?

please help

Jack
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12378016
what is your mean of exclude a certain Cell from printing ?
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 12378262
i will not include when i print the sheet.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12378320
Excel App print whatever shows on worksheet, if you don't want to show a value of particular cell, you can try to set the cell's value to empty first, then print it, and then restore your value back.

You can even set the row's height or column's width to 0 programmingly to hire it if necessary.

regards
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 12378337
ok the cell contain a textbox with its fill color to black how can i remove it? or how it will not show when i print the sheet.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12378359
Can help send me a copy of your file? I wil try look for you shortly. Find my email from my profile.

regards
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question