Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

excel

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

661 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