Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2006, 03:11 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sendkey not working

I am trying to use a get text from a program and put in Excel. I dimmed my get text and created a msgbox to show that I am actually capturing the right number, but I can not get it into excel with a sendkey command. I am very new at this and I know it is probably very easy to do, can you help?
 
Old March 14th, 2006, 09:56 AM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why do you use SendKeys?
Try work directly with Excel library.

First check the refference to Excel Object Library
Then try something like this code

Public Sub OpenExcel()
Dim objExcelApp As Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet

  Set objExcelApp = New Excel.Application
  'if you want open existing workbook
  Set objWorkbook = objExcelApp.Workbooks.Open("<filename_with_path>")
  'or if you want create new workbook
  Set objWorkbook = objExcelApp.Workbooks.Add
  objWorkbook.Name = "yourname"

  'set current working sheet
  set objSheet = objWorkbook.Worksheets(<sheet_number or sheet_name>)

  'do what you need
  objSheet.Cells(Row, Column).Value = "your_value"
  ...

  'save your work
  objWorkbook.Save

  Set objSheet = Nothing
  Set objWorkbook = Nothing
  Set objExcelApp = Nothing

End Sub

Peko

 
Old March 14th, 2006, 12:41 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this and I get subscript out of range error message on the following line.

Set objSheet = objWorkbook.Worksheets(sheet1)
 
Old March 14th, 2006, 06:58 PM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use parenthesis.
Set objSheet = objWorkbook.Worksheets("sheet1")

Peko






Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Get Working Copy... not working Enkiel Classic ASP Basics 0 April 21st, 2004 01:41 PM
SendKey commands charlie3 VBScript 1 July 6th, 2003 02:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.