Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics 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 June 21st, 2007, 04:00 PM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy data to Excel

I need to be able to copy a text file to a specific sheet in an .xls file without Excel actually installed.

I have a VBSCRIPT that works perfectly if Excel is installed, but it does not work at all if Excel is not installed.

Here is the code:

Option Explicit

Dim objApp, objWbs, objWorkbook, objWorkbook2, objSheet, WshShell, objSheet2

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /C copy \\aragorn\Phx\Wksetup\Design\TESTING\750.WK1 \\aragorn\Phx\Wksetup\Design\TESTING\750.csv", 0, True

Set objApp = CreateObject("Excel.Application")
Set objWbs = objApp.WorkBooks
objApp.Visible = False
Set objWorkbook = objWbs.Open("\\aragorn\Phx\Wksetup\Design\TESTING\ 750.wk1")
Set objWorkbook2 = objWbs.Open("\\aragorn\Phx\Wksetup\Design\TESTING\ PhxAmpBlkswk1stocsvs.xls")
Set objSheet = objWorkbook2.Sheets("750_wk1")
Set objSheet2 = objWorkbook2.Sheets("750 sort")

objWorkbook.Sheets(1).UsedRange.Copy objSheet.Range("A1")
objSheet2.PrintOut
objWorkbook2.Save

objWorkbook.Close False
objWbs.Close
objApp.Quit

Set objSheet = Nothing
Set objWorkbook = Nothing
Set objWbs = Nothing
Set objApp = Nothing

Sincerely,

George Jackson

 
Old July 1st, 2007, 07:56 AM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you havn't figured out the solutions yet.
Import Office COM's
import these
1) Microsoft.Office.Interop.Excel.dll
2) Microsoft.Vbe.Interop.dll
3) Microsoft.Vbe.Interop.Forms.dll
4) office.dll

and your code will work fine even without Office Installed.
you can download the Office 2003 Primary Interop Assemblies from
Microsoft Corp. Its a 5 MB Package that contains office assemblies which can be used to create applications that interact with Office
tools & Apps.





Similar Threads
Thread Thread Starter Forum Replies Last Post
XMLSpy: copy data from excel, paste in XMLSpy 2004 xmler XML 1 November 26th, 2008 03:33 AM
Copy data from Excel to open HTML form Bartje Excel VBA 1 September 29th, 2006 04:02 AM
Copy data from webpage to excel using vba kg8299 Excel VBA 0 April 5th, 2006 03:51 AM
Copy Data from Access.mdb into an Excel Spreadshee KennethMungwira ADO.NET 2 January 23rd, 2004 10:46 AM





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