I have code that loops through sheets of data and creates charts based on each set of data. That works great. But when I added a line to the code to add a black border to each chart (j is the index used to loop through and identify the appropriate chart):
With ActiveSheet.Shapes("MyChart" & j).Line
.ForeColor.ObjectThemeColor = msoThemeColorText1
End With
Excel displays the following message box for each chart being created when I run the code:
"Complex formatting that is applied to the selected chart may take a while to display. Do you want to continue using the formatting?
Yes/No"
The code works fine if I just keep clicking "Yes" for each chart it's creating until the code is finished, but I don't want Excel to ask this at all, I want it to just go ahead with the formatting.
Everywhere I've looked in my research for how to do this says to set:
Application.DisplayAlerts = False
But this isn't working. Excel still displays the Yes/No box every time. Are there other ways to suppress messages/alerts in Excel? Why isn't the above line of code working?
Related
I am a beginner in VBA, so be indulgent in my lack of methodology while working on some VBA macro for Excel.
My goal is to create some BoxPlot Charts in Excel at this time, I have been able to create some For/If loop to capture the Data in my different worksheets (ex: I have a Ftotal column in each worksheet, but from different length that I want to add to my boxplot). For some graphs (xlcolumnclustered, ...) I have been able to simply write:
ActiveChart.ChartType = xlColumnClustered
But, when I want to do it for a box plot (xlboxwhiskler) I have not been able to complete it. So I have tried to record a macro while I was creating a box plot graphs in a chart sheet and I have been able to capture:
ActiveSheet.Shapes.AddChart2(406, xlBoxwhisker).Select
Which is not working when I am runing my Macro. Btw way, I can't figure our why I get an Activesheet instruction whereas I was on a chart page (seems strange to me, I was expecting an ActiveChart).
So my question are:
Is there a xlboxwhiskler working to create a Box Plot Chart ?
If not, is there another way ? (I have some info from here and here). Just FMY, why is Set used for ?
Finally my last solution is about to calculate everything (it might be challenging to do so), but the link here might be useful
If you have any suggestion, I remain open for it. It will then post my solution.
I'm working on creating a PowerPoint template for daily class presentations. In the template I'd like to have a hunk of text that is prominently displayed on the first slide and which repeats at the bottom of the subsequent slides at the bottom in a smaller size. The text will change every day.
The ideas I've had so far:
Use a text field. As far as I can tell, PowerPoint doesn't have anything like a text field that can be dynamically set.
Use a footer - this works and I can modify the master to get the look I want, but I'd really like to be picking up the value of the text from the first page so that edits would be automatically applied and to save the initial step of setting the footer.
Using VBA - I'd be willing to give this a shot, but I've never used VBA and the learning curve seems steep so it would be nice to know if the idea is feasible in VBA.
Can this be done? How would you approach it?
Here's an example of what I'm hoping to be able to do. Ideally the solution would work on both the Mac (2013) and Windows (2016) version of PowerPoint.
You can connect your presentation with an excel file. And running the code in the ppt would pull out the text in the excel file and update the titles instantly.
Create a presentation with a textbox with some temporary text. Put the below code in ppt. save as pptm.
Sub AddMotionPath()
Dim Temp As String
Excel.Application.Workbooks.Open ("D:\Users\Desktop\Book1.xlsx") ' update the path of the excel file
Workbooks("Book1.xlsx").Activate 'activate the file
For p = 1 To 4
Temp = Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B" & p + 1).Value ' Column B has the titles
ActivePresentation.Slides(p).Shapes(1).TextFrame.TextRange.Text = Temp ' this updates the titles from excel to ppt slide
Next
Excel.Application.Workbooks("Book1.xlsx").Close False 'closes the excel file
End Sub
Let me know if this works for you. You can update the excel file and run the macro in ppt. The text in the slides will be updated automatically.
I have a macro in excel that creates a graph from the data is the first worksheet. The issue is that the graph is blank until i right click, select data, press ok. I don't have to actually select the data the values are already populated. Once I do this the graph looks fine. How do I get the graph to show the values without having to manually do this?
ActiveSheet.Shapes.AddChart2(240, xlXYScatterLinesNoMarkers).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = Sheets(1).Range("C1")
ActiveChart.FullSeriesCollection(1).XValues = Sheets(1).Range("AB:AB")
ActiveChart.FullSeriesCollection(1).Values = Sheets(1).Range("C:C")
Sometimes the Modules in Excel can get corrupted and the code does strange things.
Copy your code into notepad or notepad++, delete the module, add a new module, and paste the code back into the module from notepad. see if that helps. I've had to do that more than once.
I have a dialog box with a couple of buttons that launch macros to activate and change to different sheets.
The problem I am having is after I click the button, the macro activates the new sheet and I see it. But when I go to delete data, add data or try to delete a row "Nothing happens" the data on the screen is still there. If I go back to the previous sheet, the cells and rows that I had intended to delete were deleted in that sheet. It is very wierd and never seen anything like that. It appears that my macro code is note doing enough to actually change to the new sheet. I do not have this problem if I click a different sheet tab to change to it. Or if I click the dialog button to go to the new sheet and quickly do a ctrl-pgDown and Ctrl-PgUp to change from another tab and back that seems to fix the problem.
This is the code in my macro I am using to try to change to the desired tab.
Private Sub Report1Button_Click()
On Error GoTo Handler
Sheets("Report1").Activate
If StayOpenBox.Value = False Then
Unload MainMenu
End If
Exit Sub
Handler:
MsgBox "Sheet 'Report1' not found or renamed"
End Sub
Thanks for any help or suggestions
UPDATE:
Here is code that I use to call the dialog box. I have a shape on the other sheet that is assigned to this macro to open dialog box
Sub ShowMainMenu()
With UserForm1
.Show
End With
End Sub
Also there is no further code to make edits to the new sheet. My Button click simply switches to the other sheet and when I attempt to make edits manually, they are actually done on the previous sheet which is not the one I am currently looking at. So anything I do, Bold text, delete text, delete row, etc, is not done on the current sheet I am looking at, but when I return to the previous sheet the changes where made there. Im on Excel 2013, I have reproduced this problem in 2 separate files, but I will try on a different computer and older version of excel. Screenshot of my situation is below.
UPDATE 2:
I ran this xlsm file on a 2nd computer with Xls 2007 and was not having the problem. So I ran the macro on a 3rd computer that also has Excel 2013 and it is experiencing the same problem. So it is not computer specific and seems to be a problem in XLS 2013 but not in XLS 2007. I will try to find a computer with Excel 2010 to test as well, but something about this code is causing a problem in 2013 but not in older versions of excel.
When you run VBA code, it will default to using the ActiveSheet if you don't define the Sheet. When you have objects/methods that you want performed on a specific sheet, you should always specify! You can do that one of two ways:
Sheets("Report1").[Object].[Method]
'or
Sheets("Report1").[Method]
or you can pass the Sheet name to a variable and use that for shorter code
Dim Report1 As Worksheet
Set Report1 = Sheets("Report1")
Report1.[Object].[Method]
'or
Report1.[Method]
Try changing the sequence of lines in your code. I had a similar situation and it turned out that I inserted the "delete sheet" code in between the commands that were copying data from sheet1 to sheet2. When I put the deletion lines (commands) after I finished copying sheets everything started to work correctly. Many commands activate one sheet while performing and this immediately disactivates another sheet. So if you used "ActiveSheet" sommand somewhere it may be incorrectly understood - the command may be executed not on the sheet you meant.
Just use the full address for the range you are trying to manipulate, for example instead of:
Sheets("mySheet").Activate
Range("A1:B10").Cut
Sheets("myOtherSheet").Activate
Range("A1:B10").Paste
use:
Sheets("mySheet").Range("A1:A10").Cut Destination:=Sheets("myOtherSheet").Range("A1:B10")
I just had the same problem, also with Excel 2013. So even if the thread is over 9 month inactive, I want to share my solution in case somebody gets here through a Google search.
The solution was really simple. Call the userform with:
UserForm1.show vbModeless
I have another pretty perplexing problem that one of you might be able to solve. So basically I have this code to write a line graph using Excel VBA. It's made so it can be dynamic and can change if more values are added. But it's reading the first value as 0 and the last value as 0 even though they are not 0. Here is the code I'm using to put the graph on the page.
Sub createchart4()
lastA = Range("A1").End(xlDown).Row
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range("Main!$A$1:$A$" & lastA)
ActiveChart.ChartTitle.Select
ActiveChart.SeriesCollection(1).Name = "=Main!$A$1"
ActiveChart.SeriesCollection(1).Values = "=Main!$A$3:$A$" & lastA
End Sub
It's saying that A3's value is 0 when it's actually 1534 and it's also reading A10 and A11 as 0 also when they're different as well.
If you can figure this out, I would be amazed :D
The only scenario when a Chart ignores a number is when the number is stored as text. See Snapshot
How to know if the number is stored as text and how do we rectify it?
If you are using Excel 2003 then go to menu Tools | Options. Under the Error Checking Tab, ensure that the checkbox Number Stored as text is checked.
In Excel 2007/2010, click on Excel Options which can be accessed from the Office Icon in Excel 2007 or Options in the File Tab in Excel 2010.
Go to the Formulas tab and ensure that Numbers formatted as text or preceded by an apostrophe is checked.
If the above checkbox is checked then you will notice a small Green Triangle as shown in the snapshot above. Select the entire range starting from the 1st cell which has the Green Triangle. Click on the Exclamation mark. Click on Convert to number and you are done.