Solved

excel

Posted on 2002-05-02
2
201 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
[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
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

Industry Leaders: 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!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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