Search Results

Search found 1188 results on 48 pages for 'vba to c'.

Page 11/48 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Execute SQL SP in Excel VBA

    - by TheOCD
    HI I am having problem with getting all the columns back when i execute following code in excel vba. I only get 6 out of 23 columns back. Connection, command etc works fine (i can see exec command in the SQL Profiler), data headers are created for all 23 columns but i only get data for 6 column. Side Note: it's not prod level code, have missed out error handling on purpose, sp works fine in SQL management studio, ASP.Net, C# win form app, it is for Excel 2003 connecting to SQL 2008. Can someone help me troubleshoot it? Dim connection As ADODB.connection Dim recordset As ADODB.recordset Dim command As ADODB.command Dim strProcName As String 'Stored Procedure name Dim strConn As String ' connection string. Dim selectedVal As String 'Set ADODB requirements Set connection = New ADODB.connection Set recordset = New ADODB.recordset Set command = New ADODB.command If Workbooks("Book2.xls").MultiUserEditing = True Then MsgBox "You do not have Exclusive access to the workbook at this time." & _ vbNewLine & "Please have all other users close the workbook and then try again.", vbOKOnly + vbExclamation Exit Sub Else On Error Resume Next ActiveWorkbook.ExclusiveAccess 'On Error GoTo No_Bugs End If 'set the active sheet Set oSht = Workbooks("Book2.xls").Sheets(1) 'get the connection string, if empty just exit strConn = ConnectionString() If strConn = "" Then Exit Sub End If ' selected value, if <NOTHING> just exit selectedVal = selectedValue() If selectedVal = "<NOTHING>" Then Exit Sub End If If Not oSht Is Nothing Then 'Open database connection connection.ConnectionString = strConn connection.Open ' set command stuff. command.ActiveConnection = connection command.CommandText = "GetAlbumByName" command.CommandType = adCmdStoredProc command.Parameters.Refresh command.Parameters(1).Value = selectedVal 'Execute stored procedure and return to a recordset Set recordset = command.Execute() If recordset.BOF = False And recordset.EOF = False Then Sheets("Sheet2").[A1].CopyFromRecordset recordset ' Create headers and copy data With Sheets("Sheet2") For Column = 0 To recordset.Fields.Count - 1 .Cells(1, Column + 1).Value = recordset.Fields(Column).Name Next .Range(.Cells(1, 1), .Cells(1, recordset.Fields.Count)).Font.Bold = True .Cells(2, 1).CopyFromRecordset recordset End With Else MsgBox "b4 BOF or after EOF.", vbOKOnly + vbExclamation End If 'Close database connection and clean up If CBool(recordset.State And adStateOpen) = True Then recordset.Close Set recordset = Nothing If CBool(connection.State And adStateOpen) = True Then connection.Close Set connection = Nothing Else MsgBox "oSheet2 is Nothing.", vbOKOnly + vbExclamation End If

    Read the article

  • Apply Font Formatting to PowerPoint Text Programatically

    - by OneNerd
    I am trying to use VBA to insert some text into a PowerPoint TextRange, I use something like this: ActiveWindow.Selection.SlideRange.Shapes("rec1").TextFrame.TextRange.Text = "Hi" However, I can't figure out how to apply bold, italic and underline programatically (I don't see a .RichText property or something similar). What I have is some simple HTML text with bold, italic and underlined text I would like to convert over. Does anyone know how to do this?

    Read the article

  • MS Access 2003 - Embedded Excel Spreadsheet on Access form

    - by Justin
    lets say I have an embedded Excel Spreadsheet on a Microsoft Access form. I call the object frame ExcelFrame and I add a text box on the form called txtA1 and I add a button on the form called cmdInsert I want to type "Hello World" into the text box, click the button and have it appear in the A1 cell on that spreadsheet. What VBA do I use to accomplish this? Thanks

    Read the article

  • violation of primary key constraint .Cannot insert duplicate key in object using ADO

    - by CREFLY
    Hi All we are working on a users apllication using Access2003(VBA) as software language and SQL Server 2005 as database. We are using ADO method and we encounter a problem. when users create new record in a ADO Screen and they want to save the record after implementing it they receive this error : error -2147217873 violation of primary key constraint 'PK_ '.Cannot insert duplicate key in object 'Pk_...' Any help will be appreciated Thanks in advance

    Read the article

  • How do you scale a pictureLink object in Excel 2010

    - by vzczc
    In Excel 2007 it is possible to scale a pictureLink object (created with the Camera Tool) using the following VBA code. With ActiveWorkbook.Sheets(sht).Pictures(name) .ShapeRange.ScaleWidth scaleValue, msoTrue .ShapeRange.ScaleHeight scaleValue, msoTrue .top = top .left = left End With This code places the picture correctly in 2010, but the scaleValue is ignored. The 2010 Excel documentation is patchy on this subject. The same code works fine in Excel 2007.

    Read the article

  • Macro for one-to-many splitting of Word documents

    - by Alex R
    I have a Word document which is several hundred pages long. I would like to use a macro to automatically create about a dozen or so sub-documents based on certain rules (mainly, occurrence of certain strings in each Section). Is this possible? What VBA functions should I read-up on? Does anybody know of any code examples which are even remotely similar and which I may be able to customize for my purposes? Thanks

    Read the article

  • QueryTables error

    - by ktm5124
    I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr, _ Destination:=ActiveSheet.Range("A1"), _ Sql:=SqlStr) .Refresh End With And yet I am getting the error: "Run-time error '1004': Application-defined or object-defined error." The debugger points to this code as the source of error. Assuming that my ConnStr and SqlStr are correct, why am I getting this error? I am using Excel 2007 and I am querying an Oracle database.

    Read the article

  • Ensuring the contacts in a Distribution List are displayed with both name and email address

    - by hawbsl
    How can I ensure the contacts I add to an Outlook distribution list are displayed with both name and email address? These contacts may not exist in any other address book, just the distribution list. Currently they show up just as an email address (in both columns). Here's roughly the VBA we're using: Do Until RS.EOF //here's where we want to inject RS!FirstName, RS!Surname etc objRecipients.Add RS!Email objRecipients.Resolve RS.MoveNext Loop Set objDistList = contactsFolder.Items.Add("IPM.DistList") objDistList.DLName = "Whatever" objDistList.AddMembers objRecipients objDistList.Save etc

    Read the article

  • Call Single StrConn from Multiple Pages

    - by Daniel
    I have a ocnnection to SQL Server set up in my vba code. The format is: strConn = "ODBC;Driver=SQL;Server=SQL1;Database=DB1;Uid=1;Pwd=1" I have this in 4 sheets, but there will be times when I will want to change it to call from SQL2 or SQL3, and instead of changing the code on each sheet 4 times, I want to change it only once. Is there a way to set up that line to run by calling it from somewhere else or by passing in a string into the ""?

    Read the article

  • New Office VBA site launch on MSDN

    MSDN now features a special site (also accessible via www.iheartmacros.com) dedicated to Microsoft Office VBA - an important part of the Office 2010 value.   The site presents a clear path for technically savvy users to begin learning how to customize the Office applications to meet their needs. This new MSDN site highlights content for: What you can do with VBA How to get started Key blogs VBA tips & tricks Access to a new interactive training tool, the Office Developer Atlas. In addition...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • VBA WinHTTPRequest and submitting forms

    - by Hazerider
    Hi. I spent all day yesterday trying to figure out how to submit a form using WinHTTPRequest. I can do it pretty easily with an InternetExplorer object, but the problem is that I need to save a PDF file that gets returned, and I am not sure how to do this with the IE object. Here is the relevant HTML code snippet: <div class="loginHome-left"> <fieldset> <h3>Log in Using</h3> <form> <label for="standardLogin" accesskey="s"> <input name="useLogin" id="standardLogin" value="standard" type="radio" checked="true">Standard Login</label> &nbsp; <label for="rsaSecurID" accesskey="r"> <input name="useLogin" value="rsaSecur" type="radio" id="rsaSecurID" onclick="redirectLogin('ct_logon_securid');return false;">RSA SecurID</label> &nbsp; <label for="employeeNTXP" accesskey="e"> <input name="useLogin" id="employeeNTXP" value="employee" type="radio" onclick="redirectLogin('ct_logon_external_nt');return false; "> Employee Windows Login<br></label> </form> <br> <div class="error">Error: ...</div><br> <form onSubmit="if(validate(this)) {formSubmit();} return false;" name="passwdForm" method="post" action="/UAB/ct_logon"> <input value="custom" name="pageId" type="hidden"> <input value="custom" name="auth_mode" type="hidden"> <input value="/UAB/ct_logon" name="ct_orig_uri" type="hidden"> <INPUT VALUE="" NAME="orig_url" TYPE="hidden"> <input value="" name="lpSp" type="hidden"> <label for="user"> <strong>Username</strong> </label> <input autocomplete="off" name="user" type="text" value="" class="txtFld" onkeypress="return handleEnter(this, event);"> <br> <label for="EnterPassword"> <strong>Password</strong>&nbsp;&nbsp;(<a tabindex="-1" href="/UAB/BCResetWithSecrets">Forgot Your Password?</a>) </label> <input autocomplete="off" name="password" type="password" class="txtFld" onkeypress="return handleEnter(this, event);"> <INPUT id="rememberLogin" name="lpCookie" type="checkbox"> <label for="rememberLogin">Remember My Login Information</label><br> </form> <div class="right"> <br> <input type="image" src="/BC_S/images/bclogin/btn_login.gif" name="" value="Submit" onClick="if(validate(document.forms['passwdForm'])){formSubmit();}return false;"> </div> <div class="clearfix"></div> </fieldset> </div> In order to log in through InternetExplorer, I do the following: Sub TestLogin() Dim ie As InternetExplorer, doc As HTMLDocument, form As HTMLFormElement, inp As Variant Set ie = New InternetExplorer ie.Visible = True ie.navigate "https://URL of the login page" Do Until ie.readyState = READYSTATE_COMPLETE Loop Set doc = ie.document For Each form In doc.forms If InStr(form.innerText, "Password") <> 0 Then form.elements("user").Value = "my_name" form.elements("password").Value = "my_password" Exit For Else End If Next 'This is the unnamed input with an image that is used to submit the form' doc.all(78).Click ie.navigate "https://url of the PDF" Do Until ie.readyState = READYSTATE_COMPLETE Loop Dim filename As String, filenum As Integer filename = "somefile.pdf" filenum = FreeFile Open filename For Binary Access Write As #filenum Write #filenum, doc.DocumentElement.innerText Close #filenum ie.Quit Debug.Print Set ie = Nothing End Sub What I really would like to do is something along the lines of the following: Sub TestLogin3() Dim whr As New WinHttpRequest, postData As String whr.Open "POST", "https://live.barcap.com/UAB/ct_logon", False whr.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" whr.setRequestHeader "Connection", "Keep-Alive" whr.Send whr.WaitForResponse postData = "user=paschom1&password=change01" 'Or the following?' postData = "user=paschom1&password=change01&orig_url=&pageId=custom&auth_mode=custom&ct_orig_uri=/BC/dispatcher&lpSp=&lpCookie=off" whr.Send postData whr.WaitForResponse Debug.Print whr.responseText End Sub It just refuses to work though. Not sure if I need to use more setRequestHeader with Content-Form or something similar, and if I do, not sure what exactly I am supposed to pass it. If anyone has any advice regarding this, it would be hugely appreciated. I could probably use a perl module to do it, but I would rather keep it all in VBA if possible. Thanks, Marc.

    Read the article

  • Get Layout Shape Corresponding to Slide Shape

    - by Ryan
    In PP2007 and using VBA, how can I get the placeholder shape on a Slide Master layout that is the "master" for a placeholder shape on the slide? I am currently using a loop to compare the position and size of the slide placeholder with the position and shape of each placeholder shape in the slide's layout, but this isn't fool-proof. For example, if the placeholder shape is moved on the slide, its position may no longer match the position of any placeholder shapes in the slide's layout. I could reapply the slide's layout to snap placeholders back into position, but that's not what I want to do. Something in the object model like "Shape.Master" would be ideal but, of course, that doesn't exist.

    Read the article

  • Get records from Access table

    - by chianta
    On Access 2010 I need to use VBA to get the records in a table, process them and put them in a new table. Could you tell me how can I do? Is there a way similar to C # to put everything into a datatable the result of a query? I found an example on how to get the data. http://pastebin.com/bCtg20jp But it always fails on the first statement "ADODB.Recordset". I went to see the included libraries and library that uses ADODB is already included "Microsoft Access 14.0 Object Library". Thanks

    Read the article

  • Disable ctrl+V paste option from excel Template in Vsto

    - by Sangram
    HI all !! I am working on excel template+ Vsto application. I have assign various custom validations and formats for various cells. But whenever i copy & paste something into the cell,these validations do not work (fails completely), is there any way so i can disable ( Ctrl+V ) Paste options from the excel template. I think it can be implemented in vba macros. But i m not sure about it. Thank you in advance. Sangram Nandkhile.

    Read the article

  • Create multiple columns on one sheet from 1 column on another with logic

    - by user450252
    I am new to VBA and I am struggling trying to make this work. I am in need of a macro that will process each cell\column on Sheet1 and put the results on Sheet2. I'm sure this is pretty easy for those who are more advanced with VB code. It contains many columns.. Anytime we encounter a — or an empty cell, we populate the cell with -999 (see the example on Sheet2) on the first column, which contains "0-2". Then we create 2 new columns and populate them with 0 on the first column and 2 on second column (see example on Sheet2). If a value is found on only one side, we then populate both sides with the same number. As each column is being process in Sheet1 and Sheet1: A B Column1 Column2 Title Title2 0–2 0–4 3 — — 5 — — — 10–23 11—29 And the results should look like this on Sheet2 Sheet2 A B C D Column1 Column1 Column2 Column2 Title-A Title-B Title-A Title-B 0 2 0 4 3 3 -999 -999 -999 -999 5 5 -999 -999 -999 -999 —999 -999 -999 -999 10 23 11 29

    Read the article

  • Check for duplicate rows in 2 columns before update

    - by user3891378
    I have a table with 4 columns, and I need to check to see if a Column Pair exists before inserting a row into the database: INSERT INTO dbo.tblCallReport_Detail (fkCallReport, fkProductCategory, Discussion, Action) VALUES (?, ?, ?, ?) The pair in question is fkCallReport and fkProductCategory. For example if the row trying to be inserted has fkCallReport = 3 and fkProductCategory = 5, and the database already has both of those values together, it should display an error and ask if they would like to combine the Disuccsion and Action with the current record. Keep in mind I'm doing this in VBA Access 2010 and am still very new.

    Read the article

  • Create macro to move data in a column UP?

    - by user1786695
    I have an excel sheet of which the data was jumbled: for example, the data that should have been in Columns AB and AC were instead in Columns B and C, but on the row after. I have the following written which moved the data from B and C to AB and AC respectively: Dim rCell As Range Dim rRng As Range Set rRng = Sheet1.Range("A:A") i = 1 lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row For Each rCell In rRng.Cells If rCell.Value = "" Then Range("AB" & i) = rCell.Offset(0, 1).Value rCell.Offset(0, 1).ClearContents End If i = i + 1 If i = lastRow + 1 Then Exit Sub End If Next rCell End Sub However, it doesn't fix the problem of the data being on the row BELOW the appropriate row now that they are in the right columns. I am new to VBA Macros so I would appreciate any help to make the data now align. I tried toggling the Offset parameter (-1,0) but it's not working.

    Read the article

  • Open excel 2007 excel files and save as 97-2003 formats in VBA

    - by ABB
    I have a weird situation where I have a set of excel files, all having the extension .xls., in a directory where I can open all of them just fine in Excel 2007. The odd thing is that I cannot open them in Excel 2003, on the same machine, without opening the file first in 2007 and going and saving the file as an "Excel 97-2003 Workbook". Before I save the file as an "Excel 97-2003 Workbook" from Excel 2007, when I open the excel files in 2003 I get the error that the file is not in a recognizable format. So my question is: if I already have the excel file opened in 2007 and I already have the file name of the open file stored in a variable, programatically how can I mimic the action of going up to the "office button" in the upper right and selecting, "save as" and then selecting "Excel 97-2003 Workbook"? I've tried something like the below but it does not save the file at all: ActiveWorkbook.SaveAs TempFilePath & TempFileName & ".xls", FileFormat:=56 Thanks for any help or guidance!

    Read the article

  • VBA ActiveX controls grow in size over Remote Desktop Connection

    - by Alistair Knock
    We have an Excel workbook with a number of ActiveX controls, running in Excel 2003 on Windows XP. When connecting using Remote Desktop, the ActiveX controls change font, sometimes font size, and sometimes orientation (in the case of a spinner control). This happens on first connection and also as the workbook is used - some of the controls then enlarge in size, often overlapping other controls and part of the workbook. I read somewhere this may be caused by improper connection management (not closing them) leading to increasing memory usage; are there other reasons why the display is so different over Remote Desktop and are there workarounds? (the properties of each control usually remain the same, so force-resizing them doesn't always have an effect)

    Read the article

  • Excel VBA - How to copy/transpose multiple columns record into individual single row

    - by larry
    I'm working on data migration, need some help on doing a macro to copy/transpose multiple columns record into individual single row. There are also a "tag" in the first row, which indicates the columns that should not be included in the copy/transpose. From: Tag x Name Jan Feb Mar Apr Larry 2 20 34 56 Harry 3 45 77 88 Marry 5 66 44 33 To: Larry Jan 2 Larry Feb 20 Larry Apr 56 Harry Jan 3 Harry Feb 45 Harry Apr 88 Marry Jan 5 Marry Feb 66 Marry Apr 33 The "Mar" data was omitted due to there's a tag (X) above it. The data might be near hundred columns (few years), and some of the months need to be omitted. Any expert able to help on this? I had been spending whole day cracking my head on this. Worse come to worse I might have to manually copy and paste, that would probably took me a decade.

    Read the article

  • VBA text box input mask

    - by Jaison
    I have two validation for date and time as below in text boxes: 00/00\ 00:00;0;0;_ It will take (dd/mm hh:mm) and works fine But sometimes i put 34/34 56:78 it will take , But it shouldn't Date sholdnot go beyond 31, month 12 time 24 and minute 59 Please help

    Read the article

  • Excel VBA to Update SQL Table

    - by user307655
    Hi All, I have a small excel program that is use to upload data to an SQL server. This has been working well for a while. My problem now is that I would like to offer to users a function to update an existing record in SQL. As each row on this table has a unique id columne. There is a column call UID which is the primary key. This is part of the code currently to upload new data: Set Cn = New ADODB.Connection Cn.Open "Driver={SQL Server};Server=" & ServerName & ";Database=" & DatabaseName & _ ";Uid=" & UserID & ";Pwd=" & Password & ";" rs.Open TableName, Cn, adOpenKeyset, adLockOptimistic For RowCounter = StartRow To EndRow rs.AddNew For ColCounter = 1 To NoOfFields rs(ColCounter - 1) = shtSheetToWork.Cells(RowCounter, ColCounter) Next ColCounter Next RowCounter rs.UpdateBatch ' Tidy up rs.Close Set rs = Nothing Cn.Close Set Cn = Nothing Is there anyway i can modify this code to update a particular UID rather than importing new records? Thanks again for your help

    Read the article

  • VBA-Sorting the data in a listbox, sort works but data in listbox not changed

    - by Mike Clemens
    A listbox is passed, the data placed in an array, the array is sort and then the data is placed back in the listbox. The part that does work is putting the data back in the listbox. Its like the listbox is being passed by value instead of by ref. Here's the sub that does the sort and the line of code that calls the sort sub. Private Sub SortListBox(ByRef LB As MSForms.ListBox) Dim First As Integer Dim Last As Integer Dim NumItems As Integer Dim i As Integer Dim j As Integer Dim Temp As String Dim TempArray() As Variant ReDim TempArray(LB.ListCount) First = LBound(TempArray) ' this works correctly Last = UBound(TempArray) - 1 ' this works correctly For i = First To Last TempArray(i) = LB.List(i) ' this works correctly Next i For i = First To Last For j = i + 1 To Last If TempArray(i) > TempArray(j) Then Temp = TempArray(j) TempArray(j) = TempArray(i) TempArray(i) = Temp End If Next j Next i ! data is now sorted LB.Clear ! this doesn't clear the items in the listbox For i = First To Last LB.AddItem TempArray(i) ! this doesn't work either Next i End Sub Private Sub InitializeForm() ' There's code here to put data in the list box Call SortListBox(FieldSelect.CompleteList) End Sub Thanks for your help.

    Read the article

  • Excel VBA Text To Column

    - by Pat
    This is what I currently have: H101 John Doe Jane Doe Jack Doe H102 John Smith Jane Smith Katie Smith Jack Smith And here is what I want: H101 John Doe H101 Jane Doe H101 Jack Doe H102 John Smith H102 Jane Smith H102 Katie Smith H102 Jack Smith Obviously I want to do this on a bigger scale. The number of columns is between 1 & 6, so I cant limit it that way. I was able to get a script that allows me to put each individual on one row. However, I am having a hard time getting the first column to copy over to each row. Sub ToOneColumn() Dim i As Long, k As Long, j As Integer Application.ScreenUpdating = False Columns(2).Insert i = 0 k = 1 While Not IsEmpty(Cells(k, 3)) j = 3 While Not IsEmpty(Cells(k, j)) i = i + 1 Cells(i, 1) = Cells(k, 1) //CODE IN QUESTION Cells(i, 2) = Cells(k, j) Cells(k, j).Clear j = j + 1 Wend k = k + 1 Wend Application.ScreenUpdating = True End Sub Like I said, it was working fine to get everyone each on their own row, but can't figure out how to get that first column. It seems like it should be so simple, but it's bugging me. Any help is greatly appreciated.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >