Posts

Showing posts with the label excel-vba

Tick Checkbox IE Automation Excel VBA

Image
Clash Royale CLAN TAG #URR8PPP Tick Checkbox IE Automation Excel VBA I'm trying to export a file from website but for that i have to select the elements i want to export from a checkbox. The HTML code for the checkbox i want to tick is: <input id="MainReport_ctl04_ctl09_divDropDown_ctl00" type="checkbox" name="MainReport$ctl04$ctl09$divDropDown$ctl00" onclick="$get('MainReport_ctl04_ctl09').control.OnSelectAllClick(this);" class=""> I've tried: With IE.document.getElementsByName("MainReport$ctl04$ctl09$divDropDown$ctl00") .Item.Click end with And With IE.document.getElementsByName("MainReport$ctl04$ctl09$divDropDown$ctl00") .Item(0).Checked = True End With And Set obj = IE.document.getElementsByName("MainReport$ctl04$ctl09$divDropDown$ctl00") obj.FireEvent ("onclick") But nothing seems to work. Could someone help me please? Thank u in advanced! ...

Connection Word --> Excel with VBA

Image
Clash Royale CLAN TAG #URR8PPP Connection Word --> Excel with VBA I'm currently working on a project within my company to create a link between Word and Excel. There are different cells in excel which should be visible in word. These cells need to be updated in Word whenever they change in Excel. I know, this isn't much of a problem because MS office does support this by creating a link between those two files. This works fine but the problem is all the documents are stored in a CRM system called Efficy. A person who works for efficy created a tool so the two documents which need to be linked are opened simultaneously in a folder. The folder is called for example "Test folder - 21001". The name of the folder changes per project in the CRM system. So if i open another project it will be called "Test folder - 21002" for example. Is it possible to create a link between Word and Excel which is always the current folder of the Word document? The excel file alw...

Can't copy sheets from one file to another

Image
Clash Royale CLAN TAG #URR8PPP Can't copy sheets from one file to another I'm new here, and was hoping to get some help with my code. So i got 2 Excel files. test1 and test2. Im trying to take 5 rows and 5 columns from one to the other. But it gives me a weird error.. Heres the code: 'rows For r As Integer = 1 To 5 'columns For c As Integer = 1 To 5 'copy the value of the cell WB2.Sheets(2).Cells(r, c).Value = WB1.Sheets(1).Cells(r, c).Value 'or text: 'WB2.Sheets(2).Cells(r, c).Text = WB1.Sheets(1).Cells(r, c).Text Next Next the loop gives me an error "HRESULT: 0x8002000B (DISP_E_BADINDEX)) Where exactly do you get this error? maybe a screenshot of what you're trying to do would help. I get the impression this is not a VBA error and that your question is missing some critical infomation. – ashleeda...

How can I URL encode a string in Excel VBA?

Image
Clash Royale CLAN TAG #URR8PPP How can I URL encode a string in Excel VBA? Is there a built-in way to URL encode a string in Excel VBA or do I need to hand roll this functionality? 14 Answers 14 No, nothing built-in ( until Excel 2013 - see this answer ). There are three versions of URLEncode() in this answer. URLEncode() A variant that supports UTF-8 encoding and is based on ADODB.Stream (include a reference to a recent version of the "Microsoft ActiveX Data Objects" library in your project): ADODB.Stream Public Function URLEncode( _ StringVal As String, _ Optional SpaceAsPlus As Boolean = False _ ) As String Dim bytes() As Byte, b As Byte, i As Integer, space As String If SpaceAsPlus Then space = "+" Else space = "%20" If Len(StringVal) > 0 Then With New ADODB.Stream .Mode = adModeReadWrite .Type = adTypeText .Charset = "UTF...

VBA: Excel 2013 autosave user desktop File Format Error

Image
Clash Royale CLAN TAG #URR8PPP VBA: Excel 2013 autosave user desktop File Format Error I have a product creation template, which filled by other users. I'd like to automatically save it to users desktop. I have to problems. First one is I'd like to save file to users desktop with predefined name. I wrote a similiar code at my last job (excel 2010) in my new job we are using excel 2013 and file paths are different. So I have to extract users desktop path, they can use pc with other languages so I'm not sure whether below code will work. CreateObject("WScript.Shell").specialfolders("Desktop") Second problem is I want to save it as "xlsm" and when I changed the file extension to ".xlsm" it didn't save. My old code which I used my last job is; ActiveWorkbook.SaveAs Environ$("UserProfile") & "My Documents" & Environ$("UserName") & " - " & Format(Date, "yyyy-mmm-dd") ...

Create a simple counter

Image
Clash Royale CLAN TAG #URR8PPP Create a simple counter This is simple on the surface but I cannot figure out how to pull it off. This is why I am coming to you guys. I want to create a button in excel, that will count numerically in a single cell the number of times the button is pushed. That is it. Any ideas on how I can pull this off? Anything you have tried so far? WE are eager to help with problems, not solve them completely for you. – Beri 46 secs ago By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Find & Replace functionality automatically formats cells to dates

Image
Clash Royale CLAN TAG #URR8PPP Find & Replace functionality automatically formats cells to dates Oftentimes when converting PDFs to excel documents, some values are distorted and inaccurate. Precisely, some cells within my "Date" Column do not contain the correct month, grammatically. For example, instead of " XX Jun ", it is " XX Iun ", where "XX" represents a day (number). XX Jun XX Iun I've resorted to use the Find & Replace functionality and it almost works perfectly, with the only caveat being that, after replacing, my cells are formatted to dates when I want them to remain as texts. What I'd therefore like resolved, if possible, is to use the Find & Replace functionality without it formatting my cells to dates after replacing, by modifying my VBA code. Sub Macro2() Dim rng As Range Set rng = Application.InputBox("Select Date Column", "Obtain Range", Type:=8) rng.Replace What:="ian", Replace...

VBA Error on opening workbook - Cannot find workbook that is there

Image
Clash Royale CLAN TAG #URR8PPP VBA Error on opening workbook - Cannot find workbook that is there I'm attempting to open a workbook, but Excel gives me an error message saying that it cannot find the workbook. Dim pricing As Workbook dim fname As String fname = Dir(ActiveWorkbook.Path & "Budget Pricing Detail*.csv") Set pricing = Workbooks.Open(Filename:=fname, UpdateLinks:=False) As you can see I'm using a wildcard to pull the file name as the last bit of the filename will be different for each instance. What's weird to me as that when Excel gives me the error box it actually names the WHOLE file (even though I never did in my code) I want it to find and says it can't find it. Also what's weird is that this was working already and all of a sudden now it isn't. 1 Answer 1 I think DIR only returns the filename, and not the entire path. Try: fname = ActiveWorkbook...

replacing .End(xlUp) with a set value

Image
Clash Royale CLAN TAG #URR8PPP replacing .End(xlUp) with a set value I am using some code I found on this site to transpose a section of a table Copy Partial Table and Insert N-times, then Transpose second part of table however I have found that it is not transposing the data beyond the last filled cell in the range being transposed, resulting in mis-alignments of the data in the resulting table. I believe it is due to the .End(xlUp) reference in the last line of the code. tws.Cells(tws.Rows.Count, dataClmStrt + 2).End(xlUp).Offset(1).Resize(38, 1).Value = Application.Transpose(rng.Offset(, dataClmStrt).Resize(, 38)) Is this the cause of the issue and if so can this term be replaced with a set value? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

VBA: filter data based on cell value and fill in to another sheet

Image
Clash Royale CLAN TAG #URR8PPP VBA: filter data based on cell value and fill in to another sheet enter image description hereI Have two Excel Sheets ("REC") & ("Training register"), "Training register" is the database. from this database I need to create Records of each employees based on their employee ID (cell value). i am searching for a VBA code that should give me the training Record a each employee once i have enter their ID in the cell and click "a command button". Attached the Excel screen short for reference. Steps 1: Enter Employee ID in the "Record" sheet Step 2: Click command button "Filter" in the Record sheet Step 3: VBA code to run and filter data from "Training register" and fill "Record". IF i Type another Employee ID in the sheet "Record" , it should ClearContents of the previous query. and produce the data. Please help me, i am not good in VBA .attached the Excel screen ...

How to separate variables and create new sheet in VBA excel?

Image
Clash Royale CLAN TAG #URR8PPP How to separate variables and create new sheet in VBA excel? So far I have this code. It does what it needs to, but I need it to do one extra step. Right now, It separates the names in the F column and creates a new worksheet for each name. However I need some names to be in the same worksheet. For Example, right now if A,B,C,D are all mixed in Column F in worksheet 1 , the current code creates 4 new worksheets, one have A, next having B, etc. But I need, for example A and B to be in the same worksheet. How can this be done? Sub company_statement() Dim lr As Long Dim ws As Worksheet Dim vcol, i As Integer Dim icol As Long Dim myarr As Variant Dim title As String Dim titlerow As Integer vcol = 6 Set ws = Sheets("Company Statement Hanley") lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row title = "A1:AE1" titlerow = ws.Range(title).Cells(1).Row icol = ws.Columns.Count ws.Cells(1, icol) = "Unique" For i = 2 To lr On Error Resume ...

VBA application.Ontime TimeValue does not run

Image
Clash Royale CLAN TAG #URR8PPP VBA application.Ontime TimeValue does not run I'm trying to get a report done and sent out at 7:00am everyday. I put Application.Ontime TimeValue("7:00:00"), "DailyReport" in my code. This ran fine in the past, but after I modified some other codes in DailyReport sub (which should not affect Application.Ontime anyway) and check "Ignore other application using DDE", the report does not fire at 7:00am anymore. Any help is greatly appreciated, guys!!!! `Option Explicit Sub DailyReport() Dim t As String 'Time to send daily Snapshot Dim pr As Boolean 'Is process running/is there data for yesterday ThisWorkbook.UpdateLink Name:="Y:DATA COLLECTION 2018.xlsx" Application.Calculate t = Db.Range("C6").Value() pr = Db.Range("D5").Value() Db.ChartObjects("Chart 1").Chart.Refresh Db.ChartObjects("Chart 3").Chart.Refresh Db.ChartObjects("Chart 4").Chart.Refresh Dim obj...

Convert comma decimals to period decimals with VBA

Image
Clash Royale CLAN TAG #URR8PPP Convert comma decimals to period decimals with VBA As the title indicates, I wish to convert comma decimals (french Canadian system) to period decimals with VBA. Other than that, Lastly, some images of what I want NOT exactly (please read the above beforehand): From this To this 1 Answer 1 Probably Ctrl+H – BrakNicku 10 mins ago @BrakNicku - true :) – Vityata 10 mins ago I think my question was too broad. There are usually way too many numbers to manually type them. Plus, they also are different (bank statements from different corporations). @vityat...

Excel VBA not retrieving data as before [on hold]

Image
Clash Royale CLAN TAG #URR8PPP Excel VBA not retrieving data as before [on hold] I want to pull data from website "http://result.biselahore.com/" to Excel Sheet by entering roll number "217449". After entering Roll Number it goes to the result card page with detail subject wise marks. To get subject-wise marks from the next page and paste it on excel, the following code is not working and it gives error number 91, "Object variable With block variable not set". Here is my entire code: Sub WData() Do Until ActiveCell.Value = "100000" Dim IE As New InternetExplorer Dim DOCS As HTMLDocument Dim str, str1, str2, str3, str4, str5 As String IE.navigate "http://result.biselahore.com/" IE.Visible = True Do DoEvents Loop Until IE.readyState = READYSTATE_COMPLETE IE.document.getElementById("rollNum").Value = ActiveCell.Value IE.document.forms(0).submit Do While IE.Busy DoEvents Loop Set DOCS = IE.document Do While DOCS.readyState <...