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 February 4th, 2009, 03:23 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default .OnAction command not taking a Variable

HELP PLZ!

I am passing a variable through an .OnAction I get everything to come out ok EXCEPT I have extra quotation marks around the variable!

I expect to see the following title for the Sub Name: MyFile.xls!'Close200002'
But in stead I get: MyFile.xls!'Close"200002"'
I am unable to get rid of the extra quotation marks (which are an invalid Sub title, otherwise I wouldn't have a problem...)
When I try to remove a set of quotation marks I get: MyFile.xls!'Close" & WOrderNum & "'
Which is obviously not what I want since it isn't taking the variable for the file name.

I'm not a VB Pro just a hack, so plz excuse the code. I'm using excel 2007 and this is only a small portion of the code I believe to be applicable.

Code:
Sub Try0()

Dim WOrderNum As String

Range("P8").Select
ThisWorkbook.Names.Add Name:="WOrderNum", RefersTo:="=$P$8", Visible:=True         

WOrderNum = Range("WOrderNum")                                             ' In this case the WOrderNum is 200002 referenced from cell P8

Range("Q8").Select                                                         ' INSERT CHECKBOX SUB FOR CLOSING
                        ActiveSheet.CheckBoxes.Add(1850, 201, 112, 10).Select
                        With Selection
                        .Name = M8
                        .LinkedCell = "L8"
                        .Value = xlOff
                        .Characters.Text = "Check Box to CLOSE WO"
                        .OnAction = "'Close""" & WOrderNum & """'"        '<=---- This is where problem is believed to exist!
                        Range("Q8").Select
                        End With

'Down here later in the code I have the Macro record a new macro titled the same as the sub attempting to be labeled above.

End Sub
This part of the program is adding check boxes for Work Orders, which are then clicked to close the work order. The sub that is executed .OnAction closes the work order. (a very annoying sub to write since I couldn't find a great way to have a macro write another macro...)

Please tell me if you have any ideas as I feel like I've tried all the quotation mark combos that can possibly exist!

thanks.
 
Old February 5th, 2009, 07:10 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Can you try

.OnAction = "'Close" & WOrderNum & "'"

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error setting menu control's OnAction property andrewafresh Excel VBA 0 February 3rd, 2009 01:26 PM
Variable Usage in Insert Command tara0308 Access VBA 7 July 30th, 2007 12:50 PM
taking particular data .. anukagni Access 2 August 4th, 2006 12:05 AM
probs while taking backup anukagni MySQL 3 April 20th, 2006 03:47 AM
CommandButton & OnAction or HyperlinkType virtualboy Excel VBA 0 October 17th, 2004 03:48 PM





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