excel-vba

“Method or Data Member Not Found” when Dim'ing Worksheet as Worksheet but not Variant

ぃ、小莉子 提交于 2020-02-02 05:45:09
问题 Consider this simple example. In a new sheet create a ActiveX Checkbox called Checkbox1 Try the following two subroutines. The first does not compile with a "Method or Data Member Not Found" error, the second one works fine. Why doesn't the first example work? Option Explicit Sub DoesntWork() Dim ws As Worksheet Set ws = Worksheets(1) MsgBox "Checkbox state is: " + CStr(ws.CheckBox1.Value) End Sub Sub Works() Dim ws As Variant Set ws = Worksheets(1) MsgBox "Checkbox state is: " + CStr(ws

Turning NUMLOCK on at the end of a macro run

醉酒当歌 提交于 2020-02-02 05:03:49
问题 What code does: I have a code that moves the mouse around the screen, takes printscreens and pastes it to excel. Problem: For some reason, my code always (with absolutely no exceptions) turns the NUMLOCK key off after every run. What I tried so far: I searched around and found the SendKeys (NUMLOCK), which in theory works (although it seems to be very problematic for users). What I want to do: I want to turn the NUMLOCK on after each macro run, Obs1: I have no idea what is causing the macro

Turning NUMLOCK on at the end of a macro run

徘徊边缘 提交于 2020-02-02 05:03:23
问题 What code does: I have a code that moves the mouse around the screen, takes printscreens and pastes it to excel. Problem: For some reason, my code always (with absolutely no exceptions) turns the NUMLOCK key off after every run. What I tried so far: I searched around and found the SendKeys (NUMLOCK), which in theory works (although it seems to be very problematic for users). What I want to do: I want to turn the NUMLOCK on after each macro run, Obs1: I have no idea what is causing the macro

VB Clear Scripting.Dictionary object

柔情痞子 提交于 2020-02-02 03:16:48
问题 I'm writing an Excel macro , and I'm having trouble clearing a Scripting.Dictionary object : Dim test As Integer test = CompListDict.Count CompListDict.RemoveAll Set CompListDict = Nothing Set CompListDict = CreateObject("Scripting.Dictionary") Dim test1 As Integer test1 = CompListDict.Count Before I do this, I add items to the dictionary, and then i try to clear it, but test1 will equal test and equal the nr of objects I've added. What am I doing wrong ? Thank you! 回答1: If I run the

Excel VBA pass parameter to OLEDBConnection

…衆ロ難τιáo~ 提交于 2020-02-01 07:36:20
问题 In an Excel workbook I have several connections to a SQL Server DB. I thought I could run a small script like the one below, but it's not doing what I want. I want to refresh the OLEDBConnection, and pass in a StartDate and EndDate, but it's not actually communicating with the connection. Sub RefreshWithDates() Dim StartDate As Date Dim EndDate As Date StartDate = Sheets("Pivot_Summary").Range("B1").Value EndDate = Sheets("Pivot_Summary").Range("B2").Value With ActiveWorkbook.Connections(

Changing an Excel cell's backcolor using hex results in Excel displaying completely different color in the spreadsheet

巧了我就是萌 提交于 2020-01-31 04:31:08
问题 So I am setting an Excel cell's Interior Color to a certain value, like below: worksheet.Cells[1, 1].Interior.Color = 0xF1DCDB; However, when I then open up the spreadsheet in Excel, I see that the color that came out is completely different (in the above case, the color in the resulting spreadsheet is 0xDCDCEF). I tried a few different colors and it always changes it, and I don't see a pattern. Is there any reason for this? I even tried setting the color by writing Color.FromArgb(241, 220,

How to get last word in a cell using Excel Formula

喜欢而已 提交于 2020-01-30 11:34:15
问题 I am trying to get the last word in a cell however, it does not seem to be appearing getting the last word of the cell. It seems to get the partial match and not working correctly. I am using =IFERROR(RIGHT(AP2,SEARCH(" ",AP2)-1),AP2) . This works great for getting the first word in a cell even where the first word is the only word in a cell. Any ideas on why this is not getting the last word correctly? 回答1: You may try this UDF which can be used in another sub routine or on the worksheet as

Save excel as PDF in current folder using current workbook name

大城市里の小女人 提交于 2020-01-30 11:32:30
问题 Trying to save a set of sheets from a workbook to PDF format to the same folder and using workbook name. After recording the macro with all the steps went back and tried to replace the pieces of the code by what I found in some of this forum's threads but now it is not working. Current version is below. What did I break? SaveToPDF Macro Sheets(Array("AUDIT Info", "REVIEW", "FILES", "WARNINGS", "PURGE", "NonBIM", _ "Clashes", "ViewsManagement")).Select Sheets("AUDIT Info").Activate ActiveSheet

Save excel as PDF in current folder using current workbook name

こ雲淡風輕ζ 提交于 2020-01-30 11:32:07
问题 Trying to save a set of sheets from a workbook to PDF format to the same folder and using workbook name. After recording the macro with all the steps went back and tried to replace the pieces of the code by what I found in some of this forum's threads but now it is not working. Current version is below. What did I break? SaveToPDF Macro Sheets(Array("AUDIT Info", "REVIEW", "FILES", "WARNINGS", "PURGE", "NonBIM", _ "Clashes", "ViewsManagement")).Select Sheets("AUDIT Info").Activate ActiveSheet

VBA to copy text from excel to on specific location in wordfile

限于喜欢 提交于 2020-01-30 11:01:09
问题 Problem: Pasting copied data from excel to specific location in a word file. Currently I have code which can paste the value, but it does so to "paragraph1" myDoc.Paragraphs(1).Range.Paste How do I specify the exact location (by line) in which to paste the data? Let me know if more info is required. Thanks! Mohd Akhtar 回答1: You could also use some bookmarks: You can choose where you put your bookmark and then write on it like this ThisDocument.Bookmarks("NAME_OF_THE_BOOKMARK").Range.Text =