excel-vba

How to put focus to textbox as needed

五迷三道 提交于 2019-12-31 04:09:46
问题 I have a textbox on a userform. If the user fails to enter anything in this textbox, I need to trap that to force an entry. I can do this easily enough, but after notifying the user tht they need to make an entry, I want the focus to return to the textbox. Right now, it doesn't do that. Here is my code: Private Sub txtAnswer_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 13: If Me.txtAnswer.Value = "" Then temp = MsgBox("You need to enter an

Show “Number stored as Text” error

心不动则不痛 提交于 2019-12-31 04:09:13
问题 I'm using an Advanced Filter, among others, with 0 and 1's. The filter works correctly only if in the Data sheet the cells with 1 and 0 have the error message "Number stored as text" displayed. For that I have to manually open the cell with double click and press Enter. Then the error message appears and the filter works. If I don't do that, the filter doesn't work. Alternatively I can click on the cell with 1 or 0 and press F2 to display the error message. Is there a way with VBA that I can

Run Time Error - Cannot access file

為{幸葍}努か 提交于 2019-12-31 04:01:32
问题 I have the following VBA script which saves a workbook and this works fine. However if commandbutton1 is clicked again it correctly brings up the option box 'Do you want to replace the file'- Yes, No, Cancel. The yes option works fine but the No and Cancel option bring up an error box - RunTime error 1004: Cannot access 'file' . Can anyone point me in the right direction to solve the problem please. Code is below: Private Sub CommandButton1_Click() Dim Path As String Dim FileName1 As String

What have I messed up in the VBA loop for each worksheet?

若如初见. 提交于 2019-12-31 04:01:25
问题 I currently have to send multiple letters out at one time and often replace only 1 or two words within a cell. The problem is that I need those words to be bolded and it would be tedious to use this macro individually on 150 worksheets. I am very new to coding and have tried to search online to edit this code to loop through all of the worksheets, but everything I try seems to only change the current sheet I am on. Below is my current code with what I thought would cause the loop, but instead

Excel VBA Formating lost on inserting characters

◇◆丶佛笑我妖孽 提交于 2019-12-31 03:59:26
问题 I have the following code which handles a double click event on one of my columns. Basically its a Notes Column so when the user double clicks it... it pops up an input and prompts for the note. The VBA code then appends a date and inserts it into the cell. I wanted the Dates to be in Bold. However when I first enter a comment the cell is correct. Like this 23/08/2013: Hi there when I double click the cell again and enter 'Hi again' the whole cell goes bold 23/08/2013: Hi there 23/08/2013: Hi

Saving .xfdf as .pdf

你说的曾经没有我的故事 提交于 2019-12-31 03:55:11
问题 I am currently using Excel to populate a PDF file with form fields. It all works but it exports it as a .xfdf. Does anyone know how I can save it as a pdf instead? FullFileName = FilePath & "Requisition - " & Trim(MyRecord.CompanyName) & " - " & _ Year & "-" & Month & "-" & Day & "-" & Hour & "-" & Minute & "-" & Seconds & ".xfdf" Open FullFileName For Output As #1 Print #1, "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" Print #1, "<xfdf xmlns=""http://ns.adobe.com/xfdf/"" xml:space="

Does ADO work with ODBC drivers or only OLE DB providers?

只愿长相守 提交于 2019-12-31 03:54:26
问题 I am trying to create some VBA code to automate dashboard creation against a PostgreSQL database. I have heard the OLE DB driver is unreliable and it looks like it hasn't been touched in several years. Does ADO work with an ODBC driver? 回答1: Yes, simply reference the DSN: oConn.Open "DSN=mySystemDSN;" & _ "Uid=myUsername;" & _ "Pwd=myPassword" 来源: https://stackoverflow.com/questions/9187811/does-ado-work-with-odbc-drivers-or-only-ole-db-providers

vbScript opens up excel but doesn't load macro/modules?

非 Y 不嫁゛ 提交于 2019-12-31 03:51:12
问题 I m in a very weird situation. I created a vbs script that would open my excel file. I had defined vba code in WorkBook_open method. I thought creating a vbs script to open up my excel would invoke my workBook_open method and execute the vba code inside it. But I was wrong. Below is my vbs code. filePath = "E:\data_extracts\mydata.xlsm" Set oExcel = CreateObject("Excel.Application") oExcel.Workbooks.Open(filepath) oExcel.Visible = True oExcel.Run "RefreshDataFromIQY" oExcel.ActiveWorkbook

Retrieve alpha characters from alphanumeric string

两盒软妹~` 提交于 2019-12-31 03:46:11
问题 How can I split up AB2468123 with excel-vba I tried something along these lines: myStr = "AB2468123" split(myStr, "1" OR "2" OR "3"......."9") I want to get only alphabet (letters) only. Thanks. 回答1: How about this to retrieve only letters from an input string: Function GetLettersOnly(str As String) As String Dim i As Long, letters As String, letter As String letters = vbNullString For i = 1 To Len(str) letter = VBA.Mid$(str, i, 1) If Asc(LCase(letter)) >= 97 And Asc(LCase(letter)) <= 122

VBA - Save SAPI speech to a GIVEN file type?

拥有回忆 提交于 2019-12-31 03:44:26
问题 My Task It's possible to use speech in Office applications. My goal to save MS SAPI speech to a given file type. AFAIK my code example saves to a WAV file. Problem I don't know, if it's possible to define the wanted file type extension only or if it's necessary to do some further setting. I didn't find an appropriate solution using VBA. Question Is there a code example how to precisely define a wanted file type, e.g. MP3, save a given text to this file type using the necessary settings