vba

Forcing documentMode when using MSHTML.HTMLDocument

断了今生、忘了曾经 提交于 2021-02-11 13:01:46
问题 Can HTMLDocument be forced to a specific documentMode when using MSHTML in Excel? So far, all properties and methods related to this seem to only return values and cannot be set (ex. documentMode, compatMode, compatible). While scraping and parsing HTML, I'm getting different behaviours in Excel on other machines in the organization which is why I want to standardize as much as I can. Code: Dim doc As HTMLDocument Set doc = New HTMLDocument Debug.Print "compatMode: " & doc.compatMode Debug

Excel VBA User-Defined Function to query an Access Database

萝らか妹 提交于 2021-02-11 12:48:57
问题 I have an Access 365 database that has Invoice Numbers, Due Dates, and Amounts Due. I'm trying to create an Excel UDF, whereby I input the Due Date and Invoice Number, and the function queries the database and returns the Amount Due. The formula result is #Value and there's no compiler error, though there appears to be an error when it attempts to open the record set (I set up a error message box for this action). Perhaps there's an issue with my SQL? I'd appreciate any assistance with this

Shell Command in VBA Execution

丶灬走出姿态 提交于 2021-02-11 12:42:33
问题 I'm trying to run two lines of commands using shell. I haven't been able to find a good source on how to actually execute shell in VBA. So far, I have been able to figure out how to open a specific directory. Sub shellCMD() Shell ("cmd.exe /k CD\Users\n808037\Desktop\OTHER") End Sub This will at least lead me to the directory where I need to go. However, now that I've gotten to the directory I need to go, I need to execute a command after. That is copy *.csv merged.csv How do I do this in

Get only the file name from MS Access file browse

…衆ロ難τιáo~ 提交于 2021-02-11 12:41:12
问题 I have the following VB code in MS Access: Private Sub Command64_Click() Dim dialog As FileDialog Set dialog = Application.FileDialog(msoFileDialogFilePicker) With dialog .AllowMultiSelect = False .Show Me.Thumbnail = .SelectedItems.Item(1) End With End Sub I'd like to only have the file name returned instead of the full path name. Is there a way to do this? 回答1: Although you can't immediately return the file name from the dialog, it's relatively simple to isolate just the file name from the

Copy random 25 files from 1300 to another folder with VBA

我与影子孤独终老i 提交于 2021-02-11 12:40:41
问题 I have 1300 excel files on a server, with revenues in them. I need to compare these revenues with one pivot file to make sure the revenues are the same in the actual 2 files. Because it is on a server, opening all of them from a server would be pretty slow, thats why I want to copy a sample of them (25 excel files) to my compter first, and then run my comparison macro from this folder. But I want to make the copying process automatized, so I somehow need to select randomly 25 of these files,

Filter Criteria1 and Criteria 2 undefined on column of Dates

被刻印的时光 ゝ 提交于 2021-02-11 12:40:16
问题 According to Microsoft: https://docs.microsoft.com/en-us/office/vba/api/excel.filter.criteria2 It is possible to set a variable = .Criteria2. This throws a runtime 1004 error in Excel 2010-2019/365. Note: if the filtered column is dates, Criteria1 and Criteria2 are undefined: Application-Defined or Object-Defined Error. Note: Excel will correctly remember Criteria1 when filtering a column of text or numbers. To simplify this for reviewers, I simply recorded a macro filtering a column of dates

Filter Criteria1 and Criteria 2 undefined on column of Dates

亡梦爱人 提交于 2021-02-11 12:40:15
问题 According to Microsoft: https://docs.microsoft.com/en-us/office/vba/api/excel.filter.criteria2 It is possible to set a variable = .Criteria2. This throws a runtime 1004 error in Excel 2010-2019/365. Note: if the filtered column is dates, Criteria1 and Criteria2 are undefined: Application-Defined or Object-Defined Error. Note: Excel will correctly remember Criteria1 when filtering a column of text or numbers. To simplify this for reviewers, I simply recorded a macro filtering a column of dates

Optimal means of obtaining cell address column letter from column index and column index from column letter

帅比萌擦擦* 提交于 2021-02-11 12:38:01
问题 Typically the accepted approach is to do the following Number to Letter public function numberToLetter(ByVal i as long) as string Dim s as string: s = cells(1,i).address(false,false) numberToLetter = left(s,len(s)-1) end function Letter to Number Public Function letterToNumber(ByVal s As String) As Long letterToNumber = Range(s & 1).Column End Function However neither of these are particular optimal, as in each case we are creating an object, and then calling a property accessor on the object

How to Monitor Multiple Folders?

风格不统一 提交于 2021-02-11 12:29:13
问题 I have code in ThisOutlookSession to do something with items I send. It checks the Sent Items folder. It works only for one specified mailbox/folder. I would like to monitor three mailboxes I can change the line: Set Items = AInbox.Items and it will work, but only for the mailbox I set it to. Private Sub Application_Startup() Dim olNs As Outlook.NameSpace Dim AInbox As Outlook.MAPIFolder Dim BInbox As Outlook.MAPIFolder Dim CInbox As Outlook.MAPIFolder Dim AItems As Items Dim BItems As Items

VBA Excel open Word Object

五迷三道 提交于 2021-02-11 12:28:50
问题 So I have a VBA and I would like to open and modify a Word file that is embedded in the Excel instead of opening it from a folder path. I am using this VBA and it is not working properly (basically I need the VBA to open the Word document, add the table from the Excel from ranges A24:C & lastRow, copy-paste everything to an Outlook email and finally close the Word document). I receive error 13, if that helps. Please assist!!!! Thanks a lot Sub SendMail() Dim ol As Outlook.Application Dim olm