What is the best way to draw in Excel using VBA? - vba

I'm a civil engineer designing a program that allows the user to define number of cross sections of a roadway and then calculate the quantity of the different materials used to build the roadway layers. I need to be able to plot a representation of the cross section that the users has defined. I'm not sure if this would be best accomplished by plotting various series on a chart, or drawing shape objects. Does anyone have any thoughts?

Yeah, not only is Excel pretty good for this, it's also pretty common to use it for this. The Newton Excel Bach blog may be where you want to spend some good time - it's an Excel for engineers site. He's got a great series on drawing with Excel. Here's one that addresses your immediate question: Drawing in Excel 7 – Creating drawings from coordinates

Since I know nothing about your problem domain or your programming skills, I can only give some general thoughts:
Excel is really good for modeling and building certain prototypes. Modeling this problem and building some charts by hand should give you and your users a good idea if the Excel solution is going to fly. If you can't get the graphics you want I would look elsewhere. Perhaps Visual Studio and Visual Basic or C#. These have mature drawing capabilities and also charting controls in recent editions.
Excel VBA has a pretty good programming layer for charts. You can also draw custom objects with VBA. I have not done this but I am sure there are references on the web. In any event, if the manually built Excel prototype looks good, it might be worthwhile to automate it with VBA.
Another factor is how many, and of what skill set will the users be? Fewer users, who know Excel pretty well make a case for using Excel. Supporting a large number of users could become onerous as it is possible to change the code in an individual file.
Finally, how long will this application be around? Versioning Excel applications can be done, but it easier to do this with more sophisticated programming environments. Also if you are going to continue to add features you might run into a wall with VBA's feature set. Hope this helps.

Related

Generating a call graph from an Excel VBA workbook

I am trying to understand some old Excel VBA code. I would like to create a call graph to help.
Quite some time ago, in other programming languages, I had a lot of success with things like VCG, but I don't know enough about VBA to decide whether such a thing is even feasible. And so far my results of searches like Excel and graph have been difficult to sift. There doesn't seem to be anything here on SO associating Excel or VBA with the existing call-graph tag.
There are some commercial products that will do this analysis.
http://www.vbdepend.com/
But you might also consider Rubberduck-VBA. It doesn't make graphs (yet), but it does do a thorough job of analyzing your code. And it's free and open-source.
Disclaimer - I'm a contributor on Rubberduck.

Using Gantt charts to track progress when working alone / with others

I wonder if anybody here uses gantt charts to track / improve own progress when working in a programming project alone or with others and what is the approach you use and which software
Gantt charts can still be useful even when working solo, since they show the critical path and easily update with new completion dates if and when things blow out (or, in those rare occasions, complete early).
Having said that, I don't usually use the charts very often any more. They're a nice picture for upper management levels but, when working alone, I just have the expected times for each task along with the expected dates (in textual format).
I find it hard to justify using an incredibly powerful project management tool when I can get the same information from a simple spreadsheet (with a lot less effort).
When you're managing a team with tasks allocated to a larger number of people then, yes, I still find the charts indispensable. But part of the reason for that is that they have to go up to higher management levels (the kind who can't understand what's going on without a pretty picture).
I use the Gantt diagram on the redmine forge: you insert tickets with deadlines and it generates the Gantt diagram.
You can also show only open tickets, closed tickets, etc.

Google Apps macros - how do they compare to Office VBA macros?

Do any of you use the javascript macro capabilities of Google Apps, particularly for spreadsheets? How do the capabilities compare? Is there anything that Google Apps can't do that can be done with VBA macros?
I am in the middle of conversion of a complex project from VBA to Google Apps Script as an experiment to see what can be done and what can't.
In general, the development environment for google apps script is primitive and frustrating. The language is of course javaScript so if you already know that then you have a head start. The problem though is that many of the advantages of javaScript are not realizable since you don't actually have access to DOM elements, and neither do you have an equivalent of Excel shapes - except through the UI object- which is essentially the same as an excel form, with the same kind of events and objects etc.
Another issue is general slowness. You need to be careful how you structure, so that you minimize calls to the spreadsheet data (I got round this by building a values cache), and scalability is very questionable.
I am equally at home with javaScript or VBA, so putting language aside, VBA is currently more fulfilling and quicker to get things done, although there are increasing capabilities built in to apps script to make it extremely promising.
I am logging the progress of my migration, and the things I come across and the battles to figure out how to minimize structural change (I am trying to see if I can come up with something that would allow dual maintenance on both platforms), so if you are interested, you can follow along here
http://ramblings.mcpher.com/Home/excelquirks/gooscript
Bruce
The VBA in Office has been the same for about 10 years now, still using old VB6. The limitations of that language are endless. No data structures, no logic short-circuiting, limited types, non-object oriented. Google Apps and javascript are presumably on the forefront of technology and so it should not have many of these limitations.
As for what each is capable of doing that the other can't, that's a little more difficult to assert. I would argue that both languages are more or less turing complete, so while it may be more or less difficult to do something in each language, in theory, a good enough team of programmers could do just about anything in either.
Cheers :D
I'm trying to create charts in google spreadsheet using google apps script and is seems not possible... It is fairly easy in VBA, maybe vb6 is 10 years old but on the other hand you're able to do everything what you need with your spreadsheet. This is not the case in google scripts though.
One of the major hurdles is that Google Apps is web based. Thats were most companies cringe at the thought that you would have your own data not stored securely within your own network. I would never trust Google with that sort of data. I'm sure they have secure data connectors, but why take that risk?
Sure VBA is outdated, and not as sexy as javascript. However, its a great tool for quickly writing small applications, and getting it to the user fast. You only really hear nightmare stories about applications that were built by non-programmers using VBA.
It really depends on your project, and what you want to accomplish. Both have their limitations.
Having taken a quick look at Google Spreadsheet API I get the impression that its currently somewhat limited, for instance:
fewer Events, no control of calculation?, no way of writing UDFs?
Has anyone tried using it for serious work?
By its nature, a Google spreadsheet will not be able to do many things a local program will do. Example: a macro that would import all csv files in a user specified folder and consolidate them.
One thing that springs to mind is that VBA has full access to the WinAPI through 'Declare Function' declarations. Google Apps script won't have this access. This is something to watch for if you're converting a spreadsheet between the two.

Reading PowerPoint Animation Effects with VBA

I have been working with PowerPoint VBA, and have a grasp on most things.
What I am struggling with is reading the effect/animation settings for each object.
I seem to be able to get a lot of what I need through the Powerpoint.ActivePresentation.Slides(slide_id).TimeLine.MainSequence(seq_num)
What confuses me is how to convert the numeric value of Powerpoint.ActivePresentation.Slides(slide_id).TimeLine.MainSequence(seq_num).EffectType to an effect (so looking for a table of values to effects or perhaps a CONST table).
Also, how to read in all the different level of effects (like entrance, or emphasis, etc) is really confusing. not to mention I cannot wrap my head around the timeline (which seems like it is not really a timeline).
Can anyone point me to any good articles or documentation that discusses how to read the effects and animations properly and fully?
If you have some specific code that can demonstrate what is happening versus what you're after, that may be more helpful in determining what is failing for you. As far as I can discern, you're looking for a way to see the constants for the EffectType values, is that correct? Have you tried the EffectInformation object?
Here are some good primers on Animation in general:
MSDN:
Creating Animation Sequences in
PowerPoint 2002 and PowerPoint 2003
(Part 1)
Creating Animation Sequences in
PowerPoint 2002 and PowerPoint 2003
(Part 2)
MVP Article
Timeline – The animation engine in
PowerPoint 2002/2003 - Part I
(there never was a Part II
published)
Note that PowerPoint 2002 throught to 2010 uses the new Animation engine so all/most 2002 samples will be applicable to later versions.
For enumerations of the various effect values, see: https://learn.microsoft.com/en-us/office/vba/api/powerpoint(enumerations)

Resources for learning VBA if you already familiar with java and ruby

I would like to learn some VB because I am interested in a few industries that tend to use it exclusively. However, I find most resources far to slow in teaching the language and tools because they are aimed for those who haven't programmed before. Is there a good guide for programmers with experience in other languages like java and ruby?
Thanks,
Steven
The best way to learn is to fire up excel, or whatever version of VBA you're going to use (yes they are subtly different). Turn on the macro recorder, do some stuff, stop recording and then look at the code created. You'll immediately see some of the classes created, they can be looked at in more detail using the Object Explorer within the VBA environment. The syntax is just like any basic language. A couple of good practises, put the line 'Option Explicit' at the top of every source file, if not variables don't need to be declared, which is initially easy but leads to annoying bug hunts.
I'm not aware of a one stop shop to learn VBA, as you've already got programming experience it'll be a matter of unlearning some stuff - like OO, inheritance etc (yes I know VBA supports classes and interfaces but they're not the full enchilada).
BTW I noticed you tagged this as VB.Net, unfortunately VB.Net is not VBA - they're not related at all. Similarly VB and VBA are not the same although the overlap is about 90%.
Writing Excel Macros with VBA, 2nd Edition by Steven Roman, ch. 5-8 has a reasonably compact tour of VBA syntax, built-in functions, etc. You can find it on Google Books. Most of what it says should apply to VB6 as well.
There is also the Visual Basic 6.0 Programmer's Guide available for free on MSDN
However, MrTelly has the best advice if you're already familiar with programming in general. The Excel VBA editor, the macro recorder, and the F1 key are probably all you need, plus the basic help on specific syntax for control structures, etc.
This might be helpful.
Quite a few years ago a DDJ's columnist calling herself Verity Stob wrote a good summary of typical gotchas awaiting an experienced programmer starting developing with VB/VBA:
http://www.ddj.com/windows/184403996;jsessionid=HZEBCTTLEH5XGQSNDLPCKH0CJUNN2JVN?_requestid=378977
Excel is a good place to learn VBA.
A good resource is the book VB/VBA In a Nutshell