PDA

View Full Version : NEWBIE with a very basic entry question VB or VBA



Vyger
05-05-2010, 04:37 PM
My last experience with programming was many years ago back in Sinclair Spectrum days and BBC basic so please do not frown upon this very basic question.

I have a couple of needs that are going to be best served by programming.

1. The conditional edit of a large text file which will be based or various programmed rules. This is actually a .GED file as used in genealogy transfer but essentially a text file for editing purposes.

2. The creation of the same type of file from compiled data in Excel, I know the required gedcom rules so I need to read from Excel and write the required format intermingled with the Excel data.

I know the Excel option is fairly straightforward but in the Word example should I do this from within Word (VBA) or external to Word (VB), I can easily understand reading a file in line by line and writing modified output but want to get off on the right foot.

The reading of the .GED file in Word will be - read a line or sequence of lines, search for known patterns within the text and write modified lines if required some of which will be additional lines, I suppose report writing for want of a better word.

Thanks in advance for your patience.

Chris

RonMcK3
05-06-2010, 09:29 AM
Chris,

I'd suggest that under Tools > Macro, you select Start Recording Macro, then, open a copy of one of your GED files, visually search through it and manually apply your rules by editing the file, and when done, go into Tools > Macro and click Stop Recording. Next, open VBE (Visual Basic Editor) by going to Macro > Visual Basic Editor <or pressing alt-F11 in Windows> and look at your code.

This will show you how Microsoft coded the your changes in Visual Basic for Applications (VBA). Your prior knowledge of Basic will help you in incorporating your 'business rules' into your code. As you go along, you'll pick up the differences between VB (event driven) and your prior Basic which probably is/was a procedural language (sequential processing).

The following Thread posted by Dave is very helpful in seeing how to read a MS Excel file and output to a MS Word document, in this case.
http://www.vbaexpress.com/forum/showthread.php?t=28845 You can see my struggles with the topic in this other thread: http://www.vbaexpress.com/forum/showthread.php?t=29449

And, above all else, return here often, consult the KB (knowledge base), search the threads, ask questions, and join the conversation. There are a lot of very knowledgeable and helpful folks around here.

Cheers!:thumb

Vyger
05-06-2010, 10:21 AM
Thanks Ron, I know once I get started on the right track with a bit of insight I will be fine. Your tip about recording and then inspecting the code sounds just the insight I need and I would never have thought of it.

:friends:

RonMcK3
05-06-2010, 10:39 AM
Chris,

Someone mentioned it to me, early on.

Cheers!

fumei
05-07-2010, 09:07 AM
"should I do this from within Word (VBA) or external to Word (VB), "

If you want to use Word, then use Word. Yes, you could write a compiled VB executable, but is there really as point?

Essentially, it seems your are manipulating strings (text), yes? If so, then my guess is if you want the output to be a Word document (which you do NOT stipulate), then use Word.