excel-vba

How to unlock and lock Excel cells for running a macro

左心房为你撑大大i 提交于 2020-01-13 18:18:27
问题 I have a spreadsheet that has two buttons - To retrieve records from database and another one to upload changes from excel to database. The macro for retrieving records from Database is as follows. Now after retrieving the records, I want the users only to edit certain columns( here the columns from January to Scenario) so that the users, after updating those cells can click on the update button to save the changes to the database. However, I don't want them to touch the other columns ( EmpID

Referencing Workbook and Worksheet by Variables

杀马特。学长 韩版系。学妹 提交于 2020-01-13 17:05:48
问题 What is the proper syntax for referencing a different workbook's worksheet? The following code is throwing an error on the last line. Thanks! 'Instantiate Workbook variables Dim mWB As Workbook 'master workbook 'Instantiate Worksheet variables Dim mWS As Worksheet 'master worksheet 'Open Workbook, set variables and reference range Workbooks.Open ("Local 500GB HD:Users:user:Public:file.xlsx") Set mWB = ActiveWorkbook Set mWS = Sheets("Invoices") mWB.mWS.Range("A1").FormulaR1C1 = "Import Date"

Referencing Workbook and Worksheet by Variables

心不动则不痛 提交于 2020-01-13 17:03:25
问题 What is the proper syntax for referencing a different workbook's worksheet? The following code is throwing an error on the last line. Thanks! 'Instantiate Workbook variables Dim mWB As Workbook 'master workbook 'Instantiate Worksheet variables Dim mWS As Worksheet 'master worksheet 'Open Workbook, set variables and reference range Workbooks.Open ("Local 500GB HD:Users:user:Public:file.xlsx") Set mWB = ActiveWorkbook Set mWS = Sheets("Invoices") mWB.mWS.Range("A1").FormulaR1C1 = "Import Date"

Go through all the userforms of a workbook

故事扮演 提交于 2020-01-13 12:44:50
问题 I would like to write a VBA program that prints the name of all the userforms in a workbook. For instance, if a workbook has a userform called frmHello . I just want to print UserForm: frmHello Does anyone know which collection is about userforms, and how to find the name of a userform? 回答1: This one works for me: Dim c As Object For Each c In ThisWorkbook.VBProject.VBComponents If c.Type = 3 Then MsgBox c.Name End If Next 来源: https://stackoverflow.com/questions/23547832/go-through-all-the

Go through all the userforms of a workbook

大兔子大兔子 提交于 2020-01-13 12:35:01
问题 I would like to write a VBA program that prints the name of all the userforms in a workbook. For instance, if a workbook has a userform called frmHello . I just want to print UserForm: frmHello Does anyone know which collection is about userforms, and how to find the name of a userform? 回答1: This one works for me: Dim c As Object For Each c In ThisWorkbook.VBProject.VBComponents If c.Type = 3 Then MsgBox c.Name End If Next 来源: https://stackoverflow.com/questions/23547832/go-through-all-the

Go through all the userforms of a workbook

安稳与你 提交于 2020-01-13 12:34:01
问题 I would like to write a VBA program that prints the name of all the userforms in a workbook. For instance, if a workbook has a userform called frmHello . I just want to print UserForm: frmHello Does anyone know which collection is about userforms, and how to find the name of a userform? 回答1: This one works for me: Dim c As Object For Each c In ThisWorkbook.VBProject.VBComponents If c.Type = 3 Then MsgBox c.Name End If Next 来源: https://stackoverflow.com/questions/23547832/go-through-all-the

How to copy and paste worksheets between Excel workbooks?

纵饮孤独 提交于 2020-01-13 11:53:12
问题 How do you transfer a worksheet from one excel app(1) to another(2) if you have two excel apps open using VBA? The problem is, the programmer uses JavaScript, and when you click on the button that transfers the web data to a xl workbook, it opens a new Excel app. I know part of the code would be: Workbooks.Add ActiveSheet.Paste ' Once I returned to the original , i.e. excel app(1). 回答1: Not tested, but something like: Dim sourceSheet As Worksheet Dim destSheet As Worksheet '' copy from the

How to fetch multiple selected sheets handles in a workbook using Excel VBA API

久未见 提交于 2020-01-13 10:49:07
问题 There is a way to select multiple Excel sheets and then do some action on them like Print. However given a workbook, how do i get to know which sheets are selected. There is a vba property Application->ActiveSheet which gives us current active sheet, but i couldn't find any way to get multiple sheets for this. 回答1: Is this what you want? Option Explicit Sub Sample() Dim ws As Worksheet Dim SelectedSheets() As String Dim n As Long, i As Long n = 0 For Each ws In ActiveWindow.SelectedSheets

IsNumeric function returning true for an empty cell

拜拜、爱过 提交于 2020-01-13 09:57:09
问题 I run a macro that copies tables from a PDF file and saves them on Excel. some of the tables contain empty cells and in my analysis I need to know the number of cells that are empty. I have a function that iterates through each column to check if the value within that cell is numeric or not. the trouble is when I run this function on an empty cell it returns true. I even tried manually cheeking the cells using the Isblank() function and it returns "false". (if I try this on any cell outside

Excel VBA Pound and Colon Signs Meaning?

点点圈 提交于 2020-01-13 09:56:06
问题 I am trying to understand a vba function with the pound and colon symbol interspersed throughout it. VBA function: kn = 1#: pn = 1#: y = 1# I know the pound sign is used to declare a variable as a double in Excel VBA. However, it does not seem to make any sense in terms of the above line. What does the above function do? 回答1: The colon ( : ) is a statement delimiter. It would be equivalent to a new line in VBA, or a semicolon in C (just to quote a random example). It allows you to write