Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

excel

Posted on 2002-05-02
2
Medium Priority
?
218 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

926 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