excel-vba

Password button and userform

纵然是瞬间 提交于 2020-06-26 16:54:09
问题 I have programmed the following userform in Excel VBA: Private Sub CommandButton1_Click() Password = TextBox1.Text If Password = a Then MsgBox "Password Correct.", vbInformation Unload Me Else MsgBox "Password Incorrect. Please try again.", vbCritical End If End Sub The password variable a = "test" This password userform itself works perfectly. Now I want to connect it to a button that is already in the sheet. The code behind this button is in the section "ThisWorkbook" in the VBA editor: Sub

Excel VBA to cross reference a Excel Table against a SQL Table

霸气de小男生 提交于 2020-06-26 14:38:26
问题 I have been using the following vba code Using Excel VBA to run SQL query (note upvoted answer in this link is the method i used) this allows me to enter a value in an excel cell and the results from sql are dumped in another column. However the problem I have now is I want to run this against multiple cells within an excel column (not just a single cell) and hopefully provide me with the status from another column (like a vlookup) from sql. I have data that contains around 20000 rows that I

Range.SpecialCells: What does xlCellTypeBlanks actually represent?

早过忘川 提交于 2020-06-26 11:29:41
问题 The Range.SpecialCells method can be used to return a Range object meeting certain criteria. The type of criteria is specified using an xlCellType constant. One of those constants (xlCellTypeBlanks) is described as referring to "Empty cells" with no further elaboration. Does anyone know what definition of "Empty" this method uses? Does it include cells with no values/formulas but various other features (data validation, normal formatting, conditional formatting, etc)? 回答1: That type includes

EXCEL VBA to Open Word, Edit and Saveas in the specified location.

两盒软妹~` 提交于 2020-06-26 07:37:35
问题 Am trying to Open the Word application, Edit, Saveas in the specified location and Need to check whether user has entered the correct Filename. Here's my code Dim Doc Dim DocPath Dim DocObj Dim VarResult DocPath = "C:\MyFolder\MyDocument.doc" Set DocObj = CreateObject("word.Application") Doc = DocObj.Documents.Open(DocPath) DocObj.Visible = True After opening the document I am doing some changes With Doc.ActiveDocument Set myRange = .Content With myRange.Find .Execute FindText:="FindText",

EXCEL VBA to Open Word, Edit and Saveas in the specified location.

ぐ巨炮叔叔 提交于 2020-06-26 07:36:22
问题 Am trying to Open the Word application, Edit, Saveas in the specified location and Need to check whether user has entered the correct Filename. Here's my code Dim Doc Dim DocPath Dim DocObj Dim VarResult DocPath = "C:\MyFolder\MyDocument.doc" Set DocObj = CreateObject("word.Application") Doc = DocObj.Documents.Open(DocPath) DocObj.Visible = True After opening the document I am doing some changes With Doc.ActiveDocument Set myRange = .Content With myRange.Find .Execute FindText:="FindText",

Setting Selection as Range

十年热恋 提交于 2020-06-26 07:26:27
问题 Can someone please hint at what i might be doing wrong here? For now I am effectively trying to do a Ctrl-A command to do a select all on a block of data in vba. Then i want that selection to be saved as a range, so that I can use it later. Dim rngAdData As Range ..... Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Set rngAdData = Selection Range(rngAdData).AdvancedFilter Action:=xlFilterInPla.... //<---- The last line gives

Renaming a sheet code name through VBA code (Not through properties)

若如初见. 提交于 2020-06-26 06:28:31
问题 I have a protected workbook A for the user which does not allow the user to copy over a sheet from another workbook B. In workbook A I consider worksheets 1-19 (only have 13 sheets as of now, I allowed 19 for future expansion of the workbook) as "system sheets" and cannot be deleted or modified. Sheets 20-30 are "non system sheets" where the user can delete and modify as needed. I'm looking to have an import function where the user can import workbook B that contains 1 sheet into workbook A.

Renaming a sheet code name through VBA code (Not through properties)

被刻印的时光 ゝ 提交于 2020-06-26 06:28:13
问题 I have a protected workbook A for the user which does not allow the user to copy over a sheet from another workbook B. In workbook A I consider worksheets 1-19 (only have 13 sheets as of now, I allowed 19 for future expansion of the workbook) as "system sheets" and cannot be deleted or modified. Sheets 20-30 are "non system sheets" where the user can delete and modify as needed. I'm looking to have an import function where the user can import workbook B that contains 1 sheet into workbook A.

Excel VBA Only User-Defined Types error

落花浮王杯 提交于 2020-06-26 04:28:08
问题 I have seen some discussion around this, but I am still puzzled by this error: Only User-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions This is what I have (and it is also possible that the problem is with the failure to assign New LookupItem (see below)): Public Type LookupItem Stock As String Price As String End Type Sub GetData() Dim PreviousPrices As Collection Dim MyStock As String Dim CurrentPrice As String Dim

Sub property in VBA Excel class module

走远了吗. 提交于 2020-06-25 05:44:31
问题 I have a module named cTask with the code below in it: Private pMile As String Public Property Get Mile() As String Mile = pMile End Property Public Property Let Mile(Value As String) pMile = Value End Property So in my sub lets say I initiate dim currtask as cTask I would like to write curtask.Mile=TIM and also curtask.Mile.stat=2 just as worksook("qqq").sheets("okko").cells(1,1)... how do I do the nested properties in my class? EDIT: so Have in one class named cTask Private pMile As cMile