Excel 2016 VBA - Problems upgrading from Excel 2013 - excel

I developed several userforms and macros for a project in Excel 2013, but when I try to test them in Excel 2016, I get multiple errors on basic VBA functions.
For example I get an "Object doesn't support this property or method" error from the following code:
Private Sub ShowImpact()
FormImpact.Show
End Sub
Another example, the following code gives me an error "Can't find project or library" on the [RIMS_tbl] table reference. This is a named table in the document:
With FormImpact.cboIndustry
.ColumnCount = 11
.ColumnWidths = "0;50;0;0;0;0;0;0;0;0;0"
.RowSource = "=RIMS!" & [RIMS_tbl].Address
.BoundColumn = 1
.TextColumn = 2
End With
As another example, I get the same error message on "Format" method in the following code:
Private Sub txtConLand_AfterUpdate()
txtConLand = Format(txtConLand.Value, "#,##0")
End Sub
Lastly, I have a label that I'm using as a background on the form, which works fine in Excel 2013, but for some reason it covers all of the other controls in 2016, and I can't send it to the back.
I'm really hoping that there is some setting in 2016 that will fix all of these problems, because I can't figure out why so many things would break between these two versions. Thanks for your help!

As mentioned in the comments above, the solution to this problem was in eliminating missing references between different version numbers. In the Visual Basic interface, go to Tools->References. Check for missing references in all versions supported. Thanks #TimWilliams and #Stefan for the solution to this problem.
I never did figure out how to fix the problem of the z-order for the background label. Even setting the v-order for that label programmatically didn't work. But I did come up with a workaround. First I made a small white bitmap file. Then under the page settings, I set the background picture to be the bitmap file. Then I set set the "PictureSizeMode" property "fmPictureSizeModeStretch," which stretched the bitmap to fit the entire page. Finally, I added a border around the entire form.

I had the same problem when migrating an VBA powered Excel from Excel 2010 to 2016. Deselecting the ATLEntityPicker 1.0 Type Library from the References list solved it.

Related

How to make double line chart not rounded in the end (how to change cap style)?

When I create a line chart in Excel and change line style to double, I can see something similar to the image below:
As you can see the beggining and ending are rounded. I want to get rid of that, so it looks like this:
It can be done by changing line "cap type". I have tried exploring Series.Format.Line methods and properties but all I can do is modify beggining/ending arrows, there is no property/method for cap. I have also tried to use excel macro recorder to try and somehow expose this property/method but I have not been successful. I have also tried to search through various Excel/VBA forums but nothing helped.
Anyone able to help with my issue? I am looking for solution in VBA and VB.NET.
It seems that this property is not exposed in VBA, so probably you are out of luck.
According to https://social.msdn.microsoft.com/Forums/en-US/577b74db-9f9d-400c-a419-1999809922da/change-chart-data-series-line-format-cap-type-in-vba:
The cap type and join type are not exposed in the VBA object model in Excel 2007 and 2010 (I don't know about Excel 2013), so the only way to set them in VBA is using the notoriously flaky SendKeys to control the Format Data Series dialog.
The article talks about office 2010, but I coudn't find any clues that this changed later.
The object that should have this information is the Format.Line-property of a data series or data point (class is LineFormat), but it shows no cap-property.
The (not so) funny thing is that the enumeration for the possible values is available in VBA:
Try this sequence of formatting (example of formatting the first series):
Dim testSeries As Series
Set testSeries = ActiveChart.SeriesCollection(1)
With testSeries.Format.Line
.DashStyle = msoLineSquareDot
.DashStyle = msoLineSolid
.Style = msoLineThinThin
End With

Excel cell locked when it is not locked

I have experienced the exact same problem as mentioned in this post.
Excel thinking cells are locked when they aren't
I tried to ask for clarification by responding / reviving the thread but it appears this is not the correct protocol. I only came across this post after numerous search string searches and this is the only relevant "hit" I could find.
My spreadsheet is similarly complex and has been running flawlessly through Excel 98, 2003 and 2010. When I use Excel 2013 (and I believe same problem happens with Excel 2016) I find cells which are unprotected (for data entry) become locked following use of a macro button, typically navigating to view a graph and then returning. Properties of the cell confirms the cell is not protected.
Reading the above post and the Microsoft links, I have only a shallow understanding of the problem i.e. SDI / Single Document Interface.
The above referenced post received a solution that was acknowledged as having resolved the issue. Perhaps I did not fully understand but no matter where I placed the code snipped it did not help me.
The code offered was:
Private Sub UserForm_Layout()
Static fSetModal As Boolean
If fSetModal = False Then
fSetModal = True
Me.Hide
Me.Show 1
End If
End Sub
There was another suggestion to try: MyForm.Show False I did not know where to pace this similarly to the main suggested code to resolve.
VBA did not like me using "Me" (Me.Hide / Me.Show 1). I tried place the code snippet in several places ... the main opening macro, the navigation macro to and from the sheet that is affected, changing "Me" to the sheet name all to no avail. It is a sheet but since the unique variables are gathered here, it may loosely be viewed as a "Form".
I used to be a competent amateur but never an expert. I am appealing for a kind person to help direct me to overcome this "Excel 2013" problem. I have tried and failed many times and spent many hours trying to fix only to find the problem is because I'm using Excel 2013. There are even now no issues using Excel 2010 which I am able to access via a friend.
I'm sorry my first post is so detailed and hopefully not over-complex. I only wanted to give the correct information about the problem.

Setting chart title only works while debugging in Excel 2016

The problem can be summarized like this:
This problem only occurs if I run the code, not when I step through the chrt.HasTitle-line. In that case, it correctly creates a title and I can edit it however I want.
I'll first give the relevant source code. This simply includes the code that distinguishes Excel 2003 from newer versions (since Excel 2003 crashes on the 'newer' code and vice versa).
Sub EnableChartTitle(chrt As Chart)
If Application.Version = "11.0" Then
EnableChartTitle_2003 chrt
Else
EnableChartTitle_Post2003 chrt
End If
End Sub
Sub EnableChartTitle_2003(chrt As Chart)
chrt.HasTitle = True
End Sub
Sub EnableChartTitle_Post2003(chrt As Chart)
chrt.SetElement msoElementChartTitleAboveChart
End Sub
The use of chrt.SetElement previously bypassed this exact issue, but now it seems to be back with Office 2016. Using the old chrt.HasTitle results in the same issue with 2016.
This code worked perfectly for all versions of Office until Office 2016. Now it suddenly refuses to enable the title unless I step through the code which is of course not the intended use.
Anyone knows what is up with this and a possible fix? VBA really gets on my nerves with this kind of stuff and it's very hard to Google too. This is where I got the previous solution from.
Here is the code that creates the chart:
Dim chrt As Chart
RI.rSheet.Activate
Set chrt = Charts.Add.Location(xlLocationAsObject, RI.rSheet.Name)
Then its location is set, any series that were auto-added are removed and new data is added using chrt.SeriesCollection.Add <range>.
Notice: The exact same code does work in another script. This is because here, there is only one series added. When setting the name of the series, Excel automatically enables the title. In this script, multiple series are added and as soon as the second set of data is added, the title is automatically removed again. Then it won't enable it again anymore.
I found an answer. You have to tell VBA twice what he has to do before he listens. Changing the code simply to
Sub EnableChartTitle_Post2003(chrt As Chart)
chrt.SetElement msoElementChartTitleAboveChart
chrt.SetElement msoElementChartTitleAboveChart
End Sub
fixed the problem.
This answer was not at all satisfactory...

Userforms causing excel 2013 to crash

I have the following issue:
I create a userform in excel 2013 and add for starters one text box to show the date and right underneath a combobox which is reflecting a data validation list.
As soon as i write the code
Private Sub UserForm_Initialize()
Me.tbDate = Date
'fill combobox
For Each cell In [cartridges]
Me.cmbCartridges.AddItem cell
Next cell
End Sub
Can anyone help pretty please?
Thanks in advance
The code should work. I am running Excel 2013 as well and just tested your code with no problems.
Two things to check.
1
Make sure that the defined name is spelled exactly the same way in the VBA code as it is in the Name Manger.
2
Make sure that the defined name does not evaluate to an error.

"Object doesn't support this action" for a drop down menu in Excel 2011 (Mac OS X)

I have a big Excel Workbook made with Office 2010 with some VBA code. Everything seems to work fine apart the drop down menus. Precisely, they work, graphically, but
Me.Shapes("Drop Down 1").ControlFormat
throws an "Object doesn't support this action" error (I am sure that "Drop Down 1" is the correct name, etc.), precisely, it gets referenced correctly (e.g. shape = Me.Shapes(1) works) but it doesn't seem to like ControlFormat. Google doesn't help much; any suggestions?
I'm quite new to VBA so there might be some trivial debugging witchcraft I'm not aware of.
EDIT: I tried creating a new workbook with a dummy dropdown menu and selecting the values whilst recording a macro but it gives no result (it's like the menu never existed).
I know this can sound frustrating and Stupid at the same time but for Excel 2011, change the line from
Me.Shapes("Drop Down 1").ControlFormat
to
Worksheets("Sheet1").Shapes("Drop Down 1").ControlFormat
For example
This will work in Excel 2010 but not in Excel 2011
Sub Sample()
With Me.Shapes("Drop Down 1").ControlFormat
.AddItem "Sid"
End With
End Sub
It will give you the error that you mentioned.
SCREENSHOT
For Excel 2011, you will have to use (Fully qualify the object)
Sub Sample()
With Worksheets("Sheet1").Shapes("Drop Down 1").ControlFormat
.AddItem "Sid"
End With
End Sub
SCREENSHOT
Note: Replace Sheet1 above with the relevant sheet name.

Resources