Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 September 24th, 2006, 11:17 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Command Button Question

Question from a newbie.

I've created code and debugged it successfully as part of a worksheet object. But when I copied the code to a command button it gives a run-time error. Why can't I simply copy the code from the worksheet to the command button?

It fails at:
    Rows("1:6").Select

and gives the reason as 'Select method of Range class failed.'

Here are the few lines of code before this line:

'
    ChDir "D:\"
    Workbooks.Open Filename:="D:\Export.csv"
' Activate export.csv
    Windows("Export.csv").Activate
' Modify the contents of the file
    Rows("1:6").Select

Thank you in advance for your help.




 
Old September 25th, 2006, 02:36 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Set your code
Rows("1:6").Select
like this
ActiveSheet.Rows("1:6").Select

-vemaju
 
Old September 25th, 2006, 08:33 PM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Vemaju; Thank you this helped.






Similar Threads
Thread Thread Starter Forum Replies Last Post
'Hidden' Command Button David Mulvey Word VBA 0 January 9th, 2007 11:21 PM
navigate b/w worksheets with command button sriramus Access VBA 1 March 26th, 2006 06:40 AM
Command Button False equivalent pinkandthebrain VB.NET 2002/2003 Basics 2 February 2nd, 2004 11:09 PM
Need to open a PDF with a command button RayL Access VBA 2 January 27th, 2004 12:53 PM
command button qry mohiddin52 Access 0 December 22nd, 2003 08:20 AM





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