Solved

excel

Posted on 2002-05-02
2
191 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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now