Solved

excel

Posted on 2002-05-02
2
196 Views
Last Modified: 2011-10-03
'Reference made to excel 8.0

Dim xlApp as excel.application
dim xlBook as excel.workbook
dim xlsheet as excel.worksheet
dim myFile as string

myFile = "C:\myfolder\myfile.xls"

Open myfile for output as #1

I want to access the worksheet pSheet and I want to add the words "help me" to cell # A4 and "please" to cell # A5

How do I do this?

0
Comment
Question by:vbWayne
2 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 100 total points
ID: 6987615
Have a look at this example from carruina  Date: 07/30/2001 PAQ Q.20160197

Insert the reference  "Microsoft Excel 8.0 Object Library"
and paste this code

The code open a Book named "C:\ExcelBook.xls"
select or insert a sheet named "Libro2"
Insert "Hello" in the cell 5,5
And save the file

Private Sub Comando0_Click()

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim aux As Excel.Worksheet
Dim exists As Boolean
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\ExcelBook.xls") 'Open
'If you want use a preformated book change the method Add to Open (path & "\name.xls")

For Each aux In xlBook.Worksheets
   If aux.Name = "Libro2" Then
       Set xlSheet = aux
       exists = True
       Exit For
   End If
Next

If Not exists Then
   Set xlSheet = xlBook.Worksheets.Add
   xlSheet.Name = "Libro2"
End If
xlApp.Visible = True

'Code to insert values

xlSheet.Cells(5, 5) = "Hello"

xlBook.Save

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

End Sub  
0
 
LVL 1

Author Comment

by:vbWayne
ID: 6988416
Not quite correct but enough to help me work out the answer and for that you get the points.Thanks for taking the time and effort.
Wayne

here is workable code in case someone looks this up.

Option Explicit
Option Compare Text

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim exists As Boolean

Private Sub cmdEnter_Click()
 Dim myBook
 myBook = "g:\pcp\balance\pcptst.xls"
 Set xlApp = CreateObject("Excel.Application")
 Set xlBook = xlApp.Workbooks.Open(myBook) 'Open
      Set xlSheet = xlBook.Worksheets(1)
     
 xlApp.Visible = True

 'Code to insert values

 xlSheet.Cells(5, 5).Value = "Hello"

 xlBook.Save
 xlBook.Application.Quit
 Set xlSheet = Nothing
 Set xlBook = Nothing
 Set xlApp = Nothing
End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

856 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