excel-vba

How can I dynamically add a radio button on a form using VBA

牧云@^-^@ 提交于 2020-01-02 20:47:32
问题 I want to dynamically add a radio button on a form, using VBA. I tried writing this code, but it crashes with 'Type Mismatch' Dim optionBtn As OptionButton Set optionBtn = UserForm1.Controls.Add("Forms.OptionButton.1", "name", True) optionBtn.Left = 10 optionBtn.Top = 10 optionBtn.Width = 30 optionBtn.Group = "q1" I also tried doing this: Dim optionBtn As Control Set optionBtn = UserForm1.Controls.Add("Forms.OptionButton.1", "name", True) optionBtn.Left = 10 optionBtn.Top = 10 optionBtn.Width

How can I dynamically add a radio button on a form using VBA

一世执手 提交于 2020-01-02 20:47:13
问题 I want to dynamically add a radio button on a form, using VBA. I tried writing this code, but it crashes with 'Type Mismatch' Dim optionBtn As OptionButton Set optionBtn = UserForm1.Controls.Add("Forms.OptionButton.1", "name", True) optionBtn.Left = 10 optionBtn.Top = 10 optionBtn.Width = 30 optionBtn.Group = "q1" I also tried doing this: Dim optionBtn As Control Set optionBtn = UserForm1.Controls.Add("Forms.OptionButton.1", "name", True) optionBtn.Left = 10 optionBtn.Top = 10 optionBtn.Width

Applying Select Case

我只是一个虾纸丫 提交于 2020-01-02 20:46:55
问题 Current code is as follows: For Each s In myReport.Sheets If s.Name = "Data" Then s.Activate Excel.ActiveWindow.Zoom = 80 End If If Left(s.Name, 7) = "Charts_" Then s.Activate Excel.ActiveWindow.Zoom = 77 End If If s.Name = "definitions" Then s.Activate Excel.ActiveWindow.Zoom = 75 End If If s.Name = "Summary" Then s.Activate Excel.ActiveWindow.Zoom = 71 End If Next Could this be made more efficient using a Select Case ? I'm unsure how to apply VBA version of select case in this context. 回答1:

Applying Select Case

江枫思渺然 提交于 2020-01-02 20:45:49
问题 Current code is as follows: For Each s In myReport.Sheets If s.Name = "Data" Then s.Activate Excel.ActiveWindow.Zoom = 80 End If If Left(s.Name, 7) = "Charts_" Then s.Activate Excel.ActiveWindow.Zoom = 77 End If If s.Name = "definitions" Then s.Activate Excel.ActiveWindow.Zoom = 75 End If If s.Name = "Summary" Then s.Activate Excel.ActiveWindow.Zoom = 71 End If Next Could this be made more efficient using a Select Case ? I'm unsure how to apply VBA version of select case in this context. 回答1:

Dynamically remove blanks from a range of excel cells

不羁岁月 提交于 2020-01-02 15:51:39
问题 I have a named range of data, called 'data'. I'm trying to find a formula or array formula that will return data in a new range of cells, but will all the blank rows missing. i.e. data is: row x y 1 A 77 2 3 B 23 4 A 100 5 And my new range is: row x y 1 A 77 3 B 23 4 A 100 It's ok if the blank rows end up at the end of the array. So far I am stumped 回答1: You should use the special cells method for this. Either with vba or Manually. Manually 2007/2010 Select column A Home Tab -Find & Select -

Export Excel Charts as Images using Powerpoint VBA

痴心易碎 提交于 2020-01-02 15:26:14
问题 I have the below code that I have written to export "Chart1" from an Excel sheet called "Sheet1" to a new slide in a created instance of powerpoint: Sub ChartsToPowerPoint() Dim pptApp As PowerPoint.Application Dim pptPres As PowerPoint.Presentation Dim pptSlide As PowerPoint.Slide Dim pptSlideCount As Integer Dim ws As Worksheet Dim intChNum As Integer Dim objCh As Object 'Open PowerPoint and create a new presentation. Set pptApp = New PowerPoint.Application Set pptPres = pptApp

Excel VBA - Loop needed for a column

大兔子大兔子 提交于 2020-01-02 15:16:16
问题 I'm very new to excel VBA and I can't figure out how to get this to work. I have a column (column K), with a header in K1. I get this spreadsheet every day and it has a different number of rows. Column K has numbers from 0-100. I need to highlight certain rows certain colors depending on the value in column K. This is what I have so far, but it just goes all the way down and makes every column red font. I need it to loop through k2 to the last K cell with a value and change the font color of

VBA - How to download .xls from website and put data into excel file

老子叫甜甜 提交于 2020-01-02 10:29:48
问题 I managed to use VBA to get to the point where I'm ready to download an excel file from the web but I'm having trouble figuring out how to actually download that file and put its contents into an excel file I'm working in. Any suggestions? Thanks Here is the code so far: Sub GetData() Dim IE As InternetExplorer Dim HTMLDoc As HTMLDocument Dim objElement As HTMLObjectElement Set IE = New InternetExplorer With IE .Visible = True .Navigate "http://www.housepriceindex.ca/default.aspx" While .Busy

VBA - How to download .xls from website and put data into excel file

倾然丶 夕夏残阳落幕 提交于 2020-01-02 10:29:44
问题 I managed to use VBA to get to the point where I'm ready to download an excel file from the web but I'm having trouble figuring out how to actually download that file and put its contents into an excel file I'm working in. Any suggestions? Thanks Here is the code so far: Sub GetData() Dim IE As InternetExplorer Dim HTMLDoc As HTMLDocument Dim objElement As HTMLObjectElement Set IE = New InternetExplorer With IE .Visible = True .Navigate "http://www.housepriceindex.ca/default.aspx" While .Busy

Runtime error 462 Excel VBA using Word

此生再无相见时 提交于 2020-01-02 10:02:25
问题 I keep getting the 462 error the second or third time I run this loop. I don't think I have any objects that are floating but maybe I missed something, I am kind of new at this. This macro is taking all the charts from Excel, pasting them into Word as pictures, resizing them, saving the document and closing it. The For loop has formatting for the chart to be pasted as a normal picture and the text below it to be caption so I can create a figure table easily. The error takes place in the