vba

I need to import data from Excel to SQL Server using VBA

回眸只為那壹抹淺笑 提交于 2021-02-08 05:48:17
问题 I am trying to import data from another Excel workbook on my PC into SQL Server. I tried with this code, but it doesn't work: Sub insertion() Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim sConnString As String Dim rsstring As String Dim m, nrows As Integer Dim loRH As Excel.ListObject Workbooks("test-vba.xls").Activate *connection* Set conn = New ADODB.Connection Set rs = New ADODB.Recordset conn.Open sConnString MsgBox "Start" Set loRH = wkb.ListObjects(1) loRH.ListColumns(1)

Excel Macro VBA - How to insert copied cells instead of paste

僤鯓⒐⒋嵵緔 提交于 2021-02-08 05:47:36
问题 I have a macro running with the following code to copy data from one Excel file into another Excel file. Currently it is copying and pasting the data into the second Excel file. This means it overwrites any data that is in the second Excel file. I would like it to insert the copied cells rather than paste over the data already in the workbook. How should I edit line 27 to make this work? I think I need to use the following code but I'm not sure how to apply it to my original code.

Adding pictures from the Web to a Powerpoint slide in VBA (MacOS)

ⅰ亾dé卋堺 提交于 2021-02-08 05:43:44
问题 I'm comfortably using VBA to iterate through a list of content in an Excel spreadsheet and creating slides in a separate Powerpoint file. That bit works. However I can't seem to add pictures to the Powerpoint presentation. I've tried: Using Shapes.AddPicture with an URL to the image. A few mention this should work; apparently it broke in some Office version (see http://www.pcreview.co.uk/forums/powerpoint-2007-vba-addpicture-web-image-problem-t3171074.html); Using Shapes.AddPicture with the

Why is freshly opened Workbook.Name different from Workbook title in Excel window?

眉间皱痕 提交于 2021-02-08 05:34:33
问题 I have created a file and referenced it as GlobalFile . Then I saved it as "Glo" and then as "Ume". Then I reopen the saved files to have two distinct workbooks open on two different names in two different Workbook objects: GlobalFile and NightMareFile . After opening, Excel windows has the correct headers as "Glo.xls" and "Ume.xls" respectively, but testing NightMareFile.Name results in "Glo.xlsx" !!! How is this possible at all? I'm on Win 10 64 bit, Excel 365 16 bit. Already tried:

Excel VBA - compare date in cell to current date

℡╲_俬逩灬. 提交于 2021-02-08 05:26:55
问题 (Excel 2010 VBA) I have a cell (A1) containing a date in the format of mmm-yy ("Custom" category). Foe example, if I enter 1/6/13 the cell shows June-13. That's fine. In my VB macro I need to check this date whether the month is the current month and whether the year is the current year. I don't care about the day. 回答1: Does this help you: Public Sub test() d = Sheet1.Range("A1") n = Now() If Year(d) = Year(n) And Month(d) = Month(n) Then MsgBox "It works" End If End Sub 回答2: Thanks to Dave

Refer to multiple selected Items in a listbox in ms-access

吃可爱长大的小学妹 提交于 2021-02-08 05:17:44
问题 How do I select multiple items in the list box, then refer to the Items I have selected? 回答1: You will need to use a variation of the following steps: create a list box on a form populate the list box using the row source. go to the other tab and change the multiselect property to extended I then used the following VBA Option Compare Database Private Item_IDs as string Private Sub List_item_id_Click() Dim i As Integer, count As Integer Dim Item_IDs As String count = 1 For i = 0 To Me.List

check if a range is empty in vba module

拈花ヽ惹草 提交于 2021-02-08 05:16:28
问题 I wanted to check if an excel range in empty in a section of code in user module. I used the below code Worksheets(yearsheet).Range("N" & rownum & ":DI").Select If Application.WorksheetFunction.CountA(Selection) = 0 Then Exit Sub End If I'm getting runtime error 1004. Can anyone tell whats my mistake? Thanks in advance. PS: rownum is integer variable and yearsheet is string variable. both these variables were updated properly in code prior to the above section of the code 回答1: "N" & rownum &

Is it possible to return error code to VBA from batch file?

一笑奈何 提交于 2021-02-08 04:58:47
问题 My batch file: SET username=%1 SET password=%2 net use "\\gessel\toys\name" %password% /user:shops\%username% ECHO.%ERRORLEVEL% :copy Xcopy "\\gessel\toys\name\babytoys" "%appdata%\shops" /S /E ECHO.%ERRORLEVEL% IF ERRORLEVEL 0 goto disconnect goto end :disconnect net use "\\gessel\toys\name\babytoys" /delete goto end :end EXIT /B %ERRORLEVEL% I have called above batch file from VBA and the code as follows: call Shell(Environ$("COMSPEC") & " /c " & path & username & password, vbHide) The

accessing individual array elements in VBA function

妖精的绣舞 提交于 2021-02-08 04:51:04
问题 VBA newbie here. I am trying to pass an array ( it is static, but please answer for dynamic range as well ) to a function. Then assign individual array elements to unique variables and use these variables in a custom formula. I just browsed around and wrote the code but keep getting #VALUE! error. The gist of the code is below: Public Function mytest(ByRef arr1 As Range) Dim A As Double Dim B As Double A = arr1(0) B = arr1(1) mytest = A + B 'The actual formula is a bit more complicated than

Number of rows based on the cell value (loop with copy)

杀马特。学长 韩版系。学妹 提交于 2021-02-08 04:49:33
问题 I would like to sync my address list with the number shown in the cell at the front sheet. The situation looks as follows: In the cell D41 I have the number of flats. Now, when I open the "Address list" sheet I want to have the first row instantly copied 40 times down (marked with red). I know, that it can be described as a loop, this is why I tried this code: Original source here: Relocation of multiple images with ID changing Private Sub AddressList() Dim i As Long Dim rg As Range, rg2 As