VBA: set txt to be printed in Portrait mode - vba

this time I'm fighting against a .txt file which doesn't want to be (programmatically) set to be printed in Portrait-mode instead of Landscape-mode (which is the default apparently).
Thing is I know how to do that with application like Word or Excel, but sadly enough I'm working on a device that has no Office at all.
I'm not providing any code at all since my problem is pretty straightforward, and I think I need a simple command in order to solve it. What I basically (programmatically) do in my subroutine is:
Open the file as #1 (I know this appears so '80, but I don't want to modify an up-and-running system, potentially having errors show up)
Write text to the file
Close #1
Save the file
Call text editor shell to show the file to the user
How can I then automatically set the print format to Portrait?
P.s.= I do not have the possibility to insert a userform or an object to print the txt file in "special ways", the user has to print the file from txt editor itself (wordpad just in case)

First to state the obvious: there are no print settings stored in text files (or indeed anything else except for the text). Print settings would be controlled within whatever you are using to print - in this case Notepad or Wordpad.
There are only very limited command line switches for Notepad and Wordpad, which unfortunately don't include page setup. In theory you may be able to automate setting portrait using SendKeys (see here and here) but if it is possible at all it's likely to be difficult and unreliable (focus and timing are two issues).
I can't see a good way round this within the parameters of your question. Adding an object within your application would probably have been the best solution. You might try looking for an alternative text editor you could install that is easier to automate. The only other alternative might be to set defaults within the printer drivers and hope that those stick when the user opens Notepad.

Related

Simulate drag & drop file to website in VBA

I have an Access database that uses VBA code to generate a GPX map file. That works fine. I then want the contents of the GPX file to be displayed on a website, https://mapy.cz
The method that the site authors intend is for users to open the site, then manually drag and drop GPX files onto the site, at which point the contents are read in and displayed by the website. This also works fine.
What I want to do is NOT require my database user to open a browser, locate the file and drag it onto the browser by hand. I want my VBA code to not only create this GPX file, but also open the user's default browser, direct it to this mapping site (all this also works okay), but then SIMULATE or FORCE the drag and drop action FROM MY VBA CODE. That is the part that on which I'm floundering. I've looked up things like using VBA's IE.Document object, and it seems to me that it should be in there somewhere, but I can't find anything that makes sense to me.
I've done similar things in the past, with SendKeys to simulate the user typing, and AutoIT to code-control a running DOS application, including reading the programs responses from the DOS screen and forcing in commands, all from VBA. It seems to me that this should be possible, and not even all that uncommon a requirement, but I've not located anything helpful in all my searching, and I've done a lot. Maybe I'm simply phrasing my searches wrong, but at this point, I'm just flat stuck.

VB.NET Opening A File From Form

I'm using the following the code to open a file that resides elsewhere on the computer:
System.Diagnostics.Process.Start(PathToOpen)
Where PathToOpen is the full address to the file I wish to open. This appears to work as intended for any file type that has an application installed that can open the file.
Whilst this works OK, if the file is on a networked drive, I want my VB.Net code to check if the file is currently in use, if so display a message. Currently what happens is if a second user tries to open the file, it opens read-only (a word file for example) which is handled outside of my application. I want to intercept before the file is opened and stop the process there.
Is this possible at all?
You are basically asking if it's possible to monitor files on a system that doesn't even belong to you ?
Word does know about a file already in use because it creates a hidden file next to the one you open. if there is already a hidden file, it means the file is already in use.
Other applications use different ways of knowing if a file they can use is already opened somewhere else.
In order to do what you want to do, you need to know how all the applications handle this problem...
A possible solution would be for you to create a small hidden file next to the file the user wants to open (just like MS Word does). Only problem, you need to destroy the file when it's closed by the user, and you have no way of knowing that...

Printing a text file using wxWidgets

I found information about wxHtmlEasyPrinting & other printing features in wxWidgets, however I didn't find something as simple as I actually needed. All I want to do is print a text file
I don't want special formatting, I want a basic printout of basic text file containing say 10 lines of text.
I have a dialog. In this dialog I have a 'print' button. The print button should take you to a print setup page, from where one can get a print out of a text file. (So the print wouldn't be actually printing the dialogue, I dont necessarily need that)
Just to make it easier to understand:
void manual::OnButton1Click(wxCommandEvent& event)
{
PrintDialog1->ShowModal();
}
Right now the above code simply shows a print setup page, but obviously, clicking on print gets you nowhere.
Any idea where to start?
Printing even a plain text file is not that simple, you still need to wrap its lines, paginate it and so on, so you do need your own wxPrintOut implementation. You can look at the printing sample included with wxWidgets to see how to do it. Or you can indeed use wxHtmlEasyPrinting after trivial conversion of the text to HTML (basically you just need to escape the special XML entities).
Another solution is to use an external program for printing, which is the absolutely simplest way to do it, but doesn't provide any UI for the user at all.

Indesign scripting - Save Copy

I'm using a Objective-C Scripting Bridge to communicate with InDesign CS3/CS4. Unfortunately I'm stuck on Save command which appears to be existing only as a part of the standard suite and not defined again in InDesign. Because of that it looks like I can Save, Save as but not Save Copy a document. Does anyone have any idea how to proceed?
Just to shortly explain the difference between Save and Save Copy - using Save Copy the current doc doesn't change which is opposite to Save or Save as.
the only other alternative other than that which philip-regan suggests. Would be to use GUI scripting but I'm still not sure what the point would be. If you wanted to save time of not closing and reopening you could save the doc make a duplicate via the finder and continue onward in indesgn with out the close and re-open bit
I always thought the distinction between Save As and Save Copy as being more semantic than anything because all that command is really doing is performing a Save As but appending the file name with " copy" (e.g., "MyLayout.indd" becomes "MyLayout copy.indd"). Just use Save as a Save Copy alternative by giving an alternate name for the document when you save it.
Edit per OP's comments: You're right that Save Copy isn't defined in the dictionary. The only way I see around this is to mimic the command's behavior by saving to a location with a new name, closing the current-yet-renamed document, and reopening the original. Not ideal, I know, but I don't see another way around it, unless Save Copy is defined in the Javascript API, which I doubt.
Well,
since Save Copy is not defined in the scripting dictionary, the only way how to proceed is to save current document a create a copy via Finder.
If you search the header file for InDesign, these are the methods that pop up:
- (InDesignDocument *) saveTo:(id)to stationery:(BOOL)stationery versionComments:(NSString *)versionComments forceSave:(BOOL)forceSave; // Save the document
- (void) saveACopyTo:(id)to stationery:(BOOL)stationery; // Saves a copy of the document.

How to Pretty print VBA code?

How do you copy VBA code into a Word document and retain the VBA editor color scheme?
You can use Notepad++ to accomplish this in three ways. Just so you know, Notepad++ is a more advanced version of Notepad, which supports syntax highlighting of different code files "out of the box" - Visual Basic included!
Download & install it, fire it up, and load up your VBA code. You should automatically see it beautifully coloured (if not, because the file extension is something other than .vb, go to Language -> VB or Language -> V -> VB).
If you need to change any of the colours, you can easily do so - just go to Settings -> Styler Configurator. From that menu, you can change the various highlighting and font options, to suit your needs - although the default usually suffices for most.
Then, go to Plugins -> NppExport. From there, you have three options you can consider:
Directly print from Notepad++
Copy all formats to clipboard
Export to RTF
Export to HTML
The first is self explanatory. The second one - "Copy all formats to clipboard" - will copy the entire file with the highlighted syntax to the clipboard. Once you click it, then open Microsoft Word or your other favourite document editor, and just hit paste! You should see the beautifully syntax-highlighted code. If something goes wrong, then you can try one of the other options (export to RTF/HTML), although I've never had a problem with the clipboard method.
There are two programs on cnet downloads, which are free to try. In case you did not try them, here are the links:
VB-VBA Code Formatter & Printer 2.2
VBAcodePrint 6.13.110
Smart Indenter could be what you're looking for? You'd load the result into Notepad++, set language to VB and save as .rtf/.doc (or print to file, can't remember off the top of my head).
For a more modern approach, Sublime Text users can install ExportHTML from Package Control. This has the added benefit of being able to include the line numbers, and changing the code coloration.
HTML files can be opened directly within Word.
Highlight supports a wide range of Operating Systems and 150+ languages including Visual Basic, although I'm not sure about VBA.
I would recommend this one: planetB
It works well with Internet Explorer (didn't work wit Firefox for me, not sure abt Chrome).
Plus it's online, so no need to install anything (the case of Company/University PC's)
Regards
Wheeliam
The following works with Visual Studio Code:
Start VS Code.
New file.
Copy & Paste the VBA code into the VS Code window.
In the lower right-hand corner, click on "Plain Text" and select "Visual Basic" instead. Note that the code is now syntax-highlighted.
Copy & Paste the formatted code into Word.