Solved

vba in excel

Posted on 2004-10-20
10
148 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
  • 7
  • 3
10 Comments
 
LVL 50

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 50

Accepted Solution

by:
Ryan Chong earned 100 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 50

Expert Comment

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

ws.PrintOut

to:

ws.PrintPreview
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 50

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 50

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 50

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 50

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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