Hot answers tagged

8 votes
Accepted

Word VBA function to find a specified heading & return its text as a string

No need for a loop at all; just use Word's built-in ability to find text based on its style and other formatting. Like so: ...
Patrick Wynne's user avatar
7 votes

Word VBA function to find a specified heading & return its text as a string

First things first, let's clean everything up. Proper descriptive naming, proper validation variables, making the code clear and obvious about what's happening where ...
Kaz's user avatar
  • 8,790
7 votes

Modularise Project and Deduplicate Code By Loading External Modules On Startup

Thanks for using Rubberduck! As @Vogel612 mentioned, the parser error you're getting is a known issue in the v1.4.3 release. In short: foo = bar(x)(y) Accessing ...
Mathieu Guindon's user avatar
7 votes

Modularise Project and Deduplicate Code By Loading External Modules On Startup

I have two tiny things right now. The variable count is a system reserved name for something else, so I would avoid naming the variable that way. ...
Raystafarian's user avatar
  • 7,129
7 votes
Accepted

Standardized and automated Class block generation for VBA

Before diving into the code itself, I'm going to go over a couple "structural things". First, I'm not entirely sure what the utility of a tool like this actually is. When I'm writing code in the ...
Comintern's user avatar
  • 4,192
7 votes

A Word macro that processes trainees' dictation, highlighting errors and checking accuracy

There are 5 steps you could take after which you could repost your code here. Use 'Option Explicit' in each module and address the errors that this will show. If you are able, install the RubberDuck ...
Freeflow's user avatar
  • 645
6 votes

Modifying a Word document template with OpenXML

Using case-sensitive string matching like that is in my opinion the first nail in the coffin. Instead a case-insensitive dictionary would be a much better option. Example: ...
t3chb0t's user avatar
  • 44.2k
5 votes
Accepted

Modifying a Word document template with OpenXML

You can replace inner foreach loops with LINQ replace if-else with switch replace ...
Vadim Ovchinnikov's user avatar
5 votes
Accepted

A Word macro that processes trainees' dictation, highlighting errors and checking accuracy

As this is a code review request, some of my comments may be considered "best practices" by me and not by others (though most of my habits I've picked up from sites and reviews such as this one). Your ...
PeterT's user avatar
  • 2,096
5 votes

A Word macro that processes trainees' dictation, highlighting errors and checking accuracy

Well that's great progress. I now have some more comments. Brute force rather than precision Your search for highlighted words is using a 'brute force' approach as you are examining every word ...
Freeflow's user avatar
  • 645
5 votes
Accepted

Document Merger using PhpDocX

Security: Credentials in ENV It is less than ideal to store your credentials in environment variables, as they may easily leak. phpinfo for example will print all ...
tim's user avatar
  • 25.1k
5 votes

Take all underlined words, put in Excel column

In the Word document Click on an underlined word In the Home menu, in the Editing section, click Select > Select Text with Similar Formatting Copy Open Excel and paste You may need to clean it up ...
user2023861's user avatar
5 votes

Export DGV data as a table to a word file using Xceed's DocX library

Yes, this code is not easy and I don't have an easy answer for you. Only a couple tips. The problem is not complexity, the problem is that the code is too long and overwhelming. First of all, you have ...
Kate's user avatar
  • 6,400
5 votes
Accepted

Export DGV data as a table to a word file using Xceed's DocX library

Review I have gone through all the code, this is a part of a single function that seems to be handling an event in the user interface, possibly a selection event on a data grid. There are 450 lines of ...
pacmaninbw's user avatar
  • 23.8k
4 votes

Copying data from an Excel sheet to Word

Those waits will kill you. A second doesn't seem like much, until you stack a lot of them together. I don't think you need to set CutCopyMode to False until the very end, either. What I would try is ...
Jon Peltier's user avatar
3 votes
Accepted

How to efficiently loop through paragraphs and make simple changes with Word VBA (Specially reverse loop to Delete Paragraphs)

Answering my Own question to share with community the Height of stupidity in my code and gradually how over 1 or 2 sleepless nights of testing, the problem was reduce to workable. First the height of ...
Ahmed AU's user avatar
  • 278
3 votes

Standardized and automated Class block generation for VBA

This post is tagged with object-oriented, but what I'm seeing is very ironically procedural code. It doesn't matter that this is "just a quick tool": we're here to write professional, quality code ...
Mathieu Guindon's user avatar
3 votes
Accepted

Take all underlined words, put in Excel column

Give this a shot. I was able to identify 30,000 underlined words out of a total 140,000 words in about 25 seconds. I also posted this on the SO question. This might a more flexible approach if you ...
Ryan Wildry's user avatar
3 votes

Converting Hindi Devanagari proprietary font to Unicode font

It's not clear why you would need to p/invoke the native MessageBoxU function, given you're not using it anywhere, correctly preferring the language's own ...
Mathieu Guindon's user avatar
3 votes
Accepted

Speeding up Python program that converts DOCX to PDF in Windows

I recently learned how easy it is to incorporate multiprocessing and multithreading into a Python program, and would like to share it with you. Python's built-in ...
Brent Pappas's user avatar
3 votes
Accepted

User interface for a simple tool that generates Word documents from Excel data

RentRosterApp If you have read any of my reviews then you know I do value consistent naming Here I can see occasional abbreviations which does not help legibility ...
Peter Csala's user avatar
  • 8,820
3 votes
Accepted

Sub that calls itself when its parent Workbook is closed

Unfortunately, the Release magic trick is dangerous because it can mess with the underlying EbMode function used by VB to ...
Cristian Buse's user avatar
2 votes

Finding and deleting a certain word

ScreenUpdating In order for you to interact with a spreadsheet (e.g. moving the mouse, selecting a cell) , the display on your monitor is re-drawn something like 30+ times per second. This takes a ...
Kaz's user avatar
  • 8,790
2 votes
Accepted

Error handling to restart Word from Excel inside a loop

The name Update_Word_DocMs_In_Folder isn't following the PascalCase convention that's otherwise observed by your code; ...
Mathieu Guindon's user avatar
2 votes
Accepted

VBA Macro - Speed decreasing with every loop iteration - substituting Word bookmarks from Excel

Naming variables Give your variables meaningful names. Characters are free and when you know what something is by looking at its name, it's so much easier to follow the code! A few examples: ...
Raystafarian's user avatar
  • 7,129
2 votes
Accepted

Handling dozens of checkbox events in a Word document

First of all, kudos for naming all these controls! You have a lot of duplication going on; extract functionality into more specialized functions/procedures. For example, this: ...
Mathieu Guindon's user avatar
2 votes

PowerShell script to Find and Replace in Word Document, including Header, Footer and TextBoxes within

COM Automation (which is what you are using) is always going to be slow. There's not much you can do about that except to try find new ways to do what you want with as few operations as possible. An ...
Dangph's user avatar
  • 1,683
2 votes
Accepted

Text extraction of document files

I would try to use bulkcopy to load all of the IDs and their CachedText at once into a staging table in Azure, and then do a single update on your document table. ...
Brandon McClure's user avatar
2 votes

PowerShell script to Find and Replace in Word Document, including Header, Footer and TextBoxes within

Shouldn't: ...
user2196947's user avatar
2 votes
Accepted

Saving and/or Printing a Word Document From C#

Error Handling Similar to the Excel part, an exception in the writing can cause an orphaned Word instance. Placing the Quit() in a finally block will help that ...
AlanT's user avatar
  • 3,599

Only top scored, non community-wiki answers of a minimum length are eligible