vba
37 TopicsChange List Selection VBA
Hi Folks! A list of items is stored on one worksheet in a workbook. By selecting an option from a dropdown menu, the item may be copied to another sheet in the workbook. I need to be able to automatically change the selection in the dropdown on the initial worksheet. Can anyone help with this? Thanks!!1.7KViews0likes1CommentCorrect formatting of Row parametr within a Worksheets Insert command
Just to show that I have set up wswkname correctly - Early in the sub the following code lines execute, in the 'initialisation' part of the sub, and the values work elsewhere perfectly well. Dim ws As Worksheet Dim wswkname As String Set ws = ActiveSheet wswkname = ws.Name I have read and understood the following example code - Worksheets(“Insert row”).Rows(“11:15”).Insert Shift:=xlShiftDown I,. though, want the literals 11 and 15 to be variables. I have assigned the necessary variables to two variables, which are named fxRI1 and fxRI2. Accordingly I wrote the following code Dim fxRI1 As Long Dim fxRI2 As Long fxRI1 = sLast_Row.Value + 3 fxRI2 = sLast_Row.Value + 4 ' sLast_Row.Value is a form value passed to the Sub Worksheets(wswkname).Rows(fxRI1:fxRI2).Insert Shift:=xlShiftDown This 'construct' would not compile though. Corrections please. Best regards Philip Bendigo, VictoriaSolved1.3KViews0likes1CommentMy whole Excel world is crumbling around me - interlinked workbooks using a lot of formulas and VBA
I have a 'set' of about a dozen spreadsheets through which I drive my family history projects. I have been having problems, for quite some time, with their opening as a 'set' and now, since the software updates which came through on 13th June, many of the interlinked formulas are just failing. Firstly when they are opened up, through a .bat file, they open up with the Internet source warning, despite the fact that all the workbooks, and all the associated xlams, are on one of my own hard drives and I created them all. I have added the directories to my safe sources list but they still come up with this message. Secondly, many of the formulas / workbook openings create messages, which say that the workbook has not been updated because the other spreadsheet was not recalculated before saving - such recalculation is not necessary in many cases. How can I remove this unnecessary check? Thirdly, some of the formulas are getting 'corrupted' every time I close the file, so that I have had to keep a text copy of the formulas in the worksheet, so that I can copy and paste the uncorrupted text of the formulas back in, every time I re-open the affected spreadsheets - this is a most annoying and time wasting activity - any ideas would be welcome, please. One thought I have had is that these 'corrupting' formulas are often quite complicated, often using quite a few nested IFs and/or VLOOKUPs [the VLOOKUPs often being ones that look across to another workbook]: would it be better if I tried to turn these formulas into my own VBA functions, maybe? With hopes for some ideas, please. I wish I could send someone the whole set of stuff, so that they could look for the flaws in my Excel use, but as a disabled pensioner I cannot afford to pay anyone, so I have to rely on Internet forums to try and get some help, please. Best regards Philip Bendigo, Victoria Australia1KViews0likes0CommentsError when refreshing OLEDB connection - "Method Refresh of Object WorkbookConnection Failed"
Hi All, I'm experiencing an issue with a workbook I've created that has VBA code embedded to refresh an OLEDB connection to SQL Server. This all works fine on computers with Excel 2013, but I have a user on Excel 2010 and it is not working on their computer. The error message is: "Run time error: '-2147417848 (80010108)': Method 'Refresh' of object 'WorkbookConnection' failed" The code is: With ActiveWorkbook.Connections("worksheet").OLEDBConnection .Connection = Array( _ "OLEDB;Provider=SQLOLEDB.1;Persist Security Info=True;User ID=User;Password=Password;Initial Catalog=InitialTable;Data Source=ServerName;" _ , _ "Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=A1234;Use Encryption for Data=False;Tag with " _ , "column collation when possible=False") .SavePassword = True .CommandText = "select * from query" ActiveWorkbook.Connections("worksheet").Refresh End With Any help or suggestions appreciated. Thanks.3.4KViews0likes0CommentsHow can you use VBA to clear Global Permissions in Power Query
How can you use VBA to reset Data source settings Under Menu Data > Get Data > Data Source Settings where my worksheet has a Data source under the radio button 'Global Permissions' ? by Clicking the "Clear Permissions" button and selecting "Clear All permissions" this will clear out all power query URL references. But, how can this be done in VBA ? with VBA I can clear data sources that are 'in current workbook' (using code below) but this will not work with the "Global Permissions". Sub RemoveConnections() For i = 1 To ActiveWorkbook.Connections.Count If ActiveWorkbook.Connections.Count = 0 Then Exit Sub ActiveWorkbook.Connections.Item(i).Delete i = i - 1 Next i End Sub5.8KViews0likes2Commentsvba sending email w/ attachment
long bit of code and im sure you all don't need all of it but its here for reference. The email portion works fine when under strBody i have text or a range with "". the problem im having is with getting it to upload a file path for an attachment. do i have to change all my code or is there just a slight typo. the WBname portion of it is a public variable defined in a different module and works like it should within its own module (the following module). Option Explicit Public Sub BlkLst_Save() Public WBname As String WBname = "BlackList" & ActiveSheet.Name & Format(Now(), "MMM dd, yyyy") Workbooks.Add ActiveWorkbook.SaveAs Filename:=WBname Workbooks("blacklist system").Activate Range("A1:F150").Select Selection.Copy Workbooks(WBname).Activate Range("A1").Select ActiveSheet.Paste End Sub so the above works fine. Below is the email portion of this and runs into an error when trying to pull from that save path as previously stated. I have bolded and italicized the portion that errors out. (**** indicate deleted information for security) Public Sub M_Emailer() 'sends email to Marik for blacklisted devices Dim CDO_Mail As Object Dim CDO_Config As Object Dim SMTP_Config As Variant Dim strSubject As String Dim strFrom As String Dim strTo As String Dim strCc As String Dim strBcc As String Dim strBody As String strSubject = "Blacklist From CDR" strFrom = "*******" strTo = "********" strCc = "" strBcc = "" strBody = C:\Users\tabor\Documents\&WBname&.xlsx Set CDO_Mail = CreateObject("CDO.Message") On Error GoTo Error_Handling Set CDO_Config = CreateObject("CDO.Configuration") CDO_Config.Load -1 Set SMTP_Config = CDO_Config.Fields With SMTP_Config .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "*******" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*******" .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 .Update End With With CDO_Mail Set .Configuration = CDO_Config End With CDO_Mail.Subject = strSubject CDO_Mail.From = strFrom CDO_Mail.To = strTo CDO_Mail.TextBody = strBody CDO_Mail.CC = strCc CDO_Mail.BCC = strBcc CDO_Mail.Send Error_Handling: If Err.Description <> "" Then MsgBox Err.Description End SubSolved7.7KViews0likes7CommentsPrinting based on Cell value - VBA???
Hello All - first time post. Not a rookie to Excel, but no expert either. I am stuck trying to automate a print function. I have a table which is 4 columns as follows: Full Name | Rating | Comments | Performed By In the "Preformed by" field, i have my staff, and there are repeats of staff. So this column (column D) has repeats of "John Smith" (3x), Sam Jones (4x), Mike Adams (1x). Each of the other columns, while there may be repeating information, should be treated as independent data (so a name of Sue Smith, which may repeat once or twice is not related to the important column of "Performed By"). I want to print each range of values for a particular staff person on an individual page (or pages if necessary) to hand out to that person individually. So is staff person John Smith has 5 reviews, that the customer name, the rating and comments all print on a single page, in a table format in the same manner as though I manually selected that range of values and printed using the "Print Selected" function. I have attached a sample spreadsheet to demonstrate. I need each staff person's reviews, customer name and rating to print on a single page based on the staff persons name. ONE CLICK or FUNCTION I have 30 staff, each with more than a few ratings to print for them, so I am looking for a way to automate this in some way, and I figure VBA is probably the best option..? I am open to providing more input as needed. Feel free to ask. Thanks so Much Justin Michigan4.9KViews1like4Commentsyes no Selection button on a msgbox
i need a msgbox says "Are you sure that you need to finalize & ws.name" vbyesno 1-if no then do nothing 2-if yes and the folder ws.name is not found then creat 3- if yes and the folder ws.name is found then msgbox says " ws.name" is already found would you like to overwrite it 4- If no do nothing 5-if yes then overwrite thanks ---------------------------------------------------------------------------------------- Private Sub CommandButton6_Click() Dim ws As Worksheet Set ws = Sheets(Sheets.Count) Dim sPath sPath = ("\\10.218.165.35\Project Managment\Correspondence\Technical Correspondence\Client-MOD\Invoices\") Application.ScreenUpdating = False Application.DisplayAlerts = False 'step1 create main folder If Dir(sPath & ws.Name, vbDirectory) = Empty Then MkDir sPath & ws.Name Dim sMain As String sMain = sPath & ws.Name & "\" 'step2 save last sheet as pdf ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ sMain & ws.Name, Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=False 'step3 save last sheet as new file/workbook ActiveWorkbook.Sheets(Sheets.Count).Copy With ActiveWorkbook .SaveAs sMain & ws.Name, 51 '<< '51=xlsx, 52=xlsm, 56=xls .Close End With Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub ------------------------1KViews0likes0CommentsUser Defined Function not showing with up "="
I have a few UDFs' that i have written for practice since i'm just getting into the programming portion of VBA. I have 3 Projects in my vba window. 1 for macros, 1 for my UDF, and the last one is whatever workbook i have opened. My question is how can i get my functions to show up when typing "=". I have searched google and the only answer that i came up with is i have to attach the module that has the function into the current workbook. My functions do work and show up when using "=" but it is a little annoying to have to attach them to every workbook i create since im dealing with new and multiple workbooks everyday. I also know that the "insert function" is under the formula tab and that works as well but still an annoyance. Just seems like there is an easier better way. Yes the functions are public, No the module names are not the same as the function name.79KViews0likes8CommentsI need a VBA script that will allow me to reference a cell(s) in ALL worksheets automatically
I have a workbook that has almost 1500 worksheets. Each worksheet is not set up as a table. Some cells may contain data or text. I am needing to pull specific cells in all worksheets into one worksheet. Doing this will allow me to create a table with the data that I want. If the workbook was smaller I could simply use a formula to return a cell, but I can't do this for nearly 1500 sheets. Can someone write me a script that will allow me to pull the data/text in a specific cell in all (almost 1500 worksheet) worksheets. I was hoping if someone did at least one, I could copy and paste or figure out how to duplicate that script to all the other cells I need. In case you need this information. The cells that I am needing are as follows: A12, A13, A14, A15, A16, A17, A18, A19, A23 B5, B6, B7, B8, B9, B12, B13, B14, B15, B16, B17, B18, B19 F6, F7, F8, F9, F10 J6, J7, J8, J9, J101.4KViews0likes2Comments