Excel中的自定义旋转button

我有我已经在工作表中分配了macros的图像,并试图应用参数,以确保只有有效的条目。 旋转button在每次单击时增加或减less单元格值1。 我已经使用数据validation标准,只允许2或更大的值(以避免负值不存在,以及使用无效的引用),但这只是限制值条目,当我手动input,而不是当使用button来降低数值时触发。

有没有办法应用一种

.Min .Max 

函数到这些形状button? 我基本上只是不希望用户能够input2以下的值。谢谢! 当前代码:

 Sub Increase_Val() Dim StartRow As Long Dim EndRow As Long Dim row_number As Long StartRow = Sheet6.Range("D5").Value EndRow = Sheet6.Range("D5").Value For row_number = StartRow To EndRow DoEvents Next row_number End Sub 

在你的旋钮macros中,你可以从单元中读取validation设置,并决定是否增加/减less数字

 Sub Tester() Dim c As Range Set c = Range("D4") If Not c.Validation Is Nothing Then If c.Validation.Type = xlValidateWholeNumber And _ c.Validation.Operator = xlBetween Then Debug.Print "Min", c.Validation.Formula1 Debug.Print "Max", c.Validation.Formula2 End If End If End Sub 

所以我的最终解决scheme结果有点不同于我所设想的。 不使用macros和图像自定义旋钮的想法,并与forms控制旋钮一起去。 完整的代码使用包含信息的定义表单中的信息,并使用个性化信息和HTML格式填充通用消息。 我的旋转button是为了帮助我select想要包含的行数(因为函数使用的是.Display方法,而不是.Send,因为我想在发送之前亲自检查每封电子邮件,并且有很多行,这使我能够更轻松地决定一次要显示多less封电子邮件)。 首先是电子邮件代码(由Alex Cantu的原创作品定制):

 Sub SendMyEmals(what_address As String, subject_line As String, mail_body_message As String) Dim olApp As Outlook.Application Dim oAttach As Outlook.Attachment Set olApp = CreateObject("Outlook.Application") Dim olMail As Outlook.MailItem Set olMail = olApp.CreateItem(olMailItem) With olMail .To = what_address .Attachments.Add = "C:\",olByValue, 0 'your directory reference, I used this for my header image", .Attachments.Add = "C:\",olByValue, 0 'other directory reference, used for footer image .Subject = "Pick your subject" .BodyFormat = olFormatHTML .HTMLBody = "<img src='cid:"Your_image_name'"&"width = 'whatever' height = 'whatever' <br> <br>" mail_body_message & "&"img src='cid:Your_other_image'" &"width = 'whatever' height = 'whatever'>" .Display End With End Sub Sub MassEmail() Dim mail_body_message As String Dim A As String Dim B As String Dim C_name As String Dim D As String Dim RowStart As String Dim RowEnd As String Dim row_number As String With Worksheets("Your_Worksheet") RowStart = SheetX.Range("Your Range").Value 'this is the sheet where I stored the generic HTML message where I used replace text to be filled in by the row ranges from the main sheet "Your_Worksheet" RowEnd = SheetX.Range("Your Other Range").Value For row_number = RowStart To RowEnd DoEvents mail_body_message = SheetX.Range("Where the HTML was stored") A = Sheet1.Range("A" & row_number) B = Sheet1.Range("B" & row_number) C = Sheet1.Range("C" & row_number) D = Sheet1.Range("D" & row_number) what_address = Sheet1.Range("D"& row_number) 'that is the column where I stored the individual email addresses mail_body_message = Replace(mail_body_message, "replace_A_here", A) mail_body_message = Replace(mail_body_message, "replace_B_here", B) mail_body_message = Replace(mail_body_message, "replace_C_here", C) mail_body_message = Replace(mail_body_message, "replace_D_here", D) Call SendMyEmails(Sheet1.Range("D"&row_number), "This is a test email", mail_body_message Next row_number End With End Sub 

无论如何,它的工作方式,我试图让它,我相信可能有更优雅的方式来做到这一点,但我现在很高兴与这个解决方法。

Interesting Posts