I need to add a bunch of DOCVARIABLES to a word document for my work. The end goal is to use C# to easily ask a user what values need to go into those variables, then automatically generate the word document from the template with empty variables.
Despite having gone through and added all the field codes for the variables, when I save the document it doesn't actually initialize any of the document variables to a state where they exist, and so when I use C#, it can't find any of them. When I check the docx as a zip file, there are no <w:docVars> tags in the settings.xml file. When I add the DOCVARIABLES using the C# instead of directly through word, those tags are added.
All of the solutions I've found so far involve using a VBA Macro to initialize them to something, but that isn't an option here because, for whatever reason, we aren't allowed to use VBA Macros at all because corporate something something. There is some restriction on the computers that corporate requires them to have that entirely prevents me from running those macros, and trying to bypass that is not an option.
How do I get the DOCVARIABLES to initialize to some initial value that will allow the C# to find them?
DocVariables cannot be blank. If you set one to a null value, it is removed.
As a workaround set an initial value to “Empty” and then have your code check for that value and take appropriate action. Otherwise, just simple check if the DocVariable exists and take appropriate action if it does not.
Update:
DocVariables must be created from a macro. The macro can be in the document, a document template, or a global add-in. All require permission to run and if the IT department won’t approve any of those solutions, then DocVariables are not really an automation option.
Related
I have a word document with a building block dropdrown to choose from several templates. I have the Word document set with a tool bar with the Send To Recipient email option. I'm trying to figure a way to get the subject line to change depending on what building block is chosen, if it's even possible.
Currently, my office is using different word files for each subject line, and I'm trying to get all templates in one file to cut down on all the different files workers need to have open at once.
Is this possible?
I have limited vb experience, but I have tried searching for macros and code that was similar to what I needed, and changing things to fit, but I'm at a loss. Anything I try outside of that just results in the subject like being static, remaining as the last edit.
What are some alternatives to using the clipboard feature in Automation Anywhere? I'm told using the clipboard feature is not ideal for consistency.
You can create a variable instead of using clipboard.
Steps to create variable:
Select the variable manager from the extreme right side of workbench window
click on Add at the bottom of variable manager section
In Add Variable window, provide the details of the variable which needs to be created
You can refer How to create variables in Automation Anywhere Client
That is True. Even if user is not using the system while AA bot is running, some background services might kick in and use clipboard(only id programmer have used it)
Note: Sometimes, depending on situation. Like a secure excel files where if we need to copy data between workbooks/sheets, we are stuck with Ctrl+C and Ctrl+V
Alternatives go as below:
1. For values, use variables instead of clipboard
2. Excel files, use Get Cell and Set Cell also consider connecting to Excel as database
3. File Copy, use the Copy File option
I cannot think of anymore scenarios as of now, but let me know what exactly were you trying to do.
You should use 'Prompt-Assignment' variable for holding temporary values. Use of 'Clipboard' should only be done where a Ctrl+C action needs to be performed however the value should immediately be transferred in 'Prompt-Assignment' or any other variable for holding the values.
You can use other system variables according to the application you are using
For ex:
Excel : Excel Column
CSV/TXT : FileData Column
These system variable will hold the values inside the loop only. you can assign in to some other custom variable and you can use it anywhere.
Due to server rights I can not access the word object and can only starts word on the client by hyperlinking in asp, such as:
file:///Z:/Prosjekt/32637/LS_32637_PR_01_A.docm
However I would like to run a spefic macros with parameters, can I somehow do this?
file:///Z:/Prosjekt/32637/LS_32637_PR_01_A.docm?NewFile.NewFile,1,"Test"
Maybe it is possible to write an on open event that parses the NewFile,1,"Test" to call NewFile.newFile(1,"test")
But I am not sure how to do so. Any hint on how to solve it would be great.
In a VBA project, I have a large SQL query that I retrieve into a string variable to form part of an operation to retrieve data from a remote database.
At present, I am storing this in plain text in a file, and I retrieve it from that file when needed.
Whilst this makes development/updates easier because I can readily edit the query in the file, it does present an exposure because a user could edit the file, possibly maliciously (limited opportunity for damage, but an unacceptable security exposure nonetheless).
The options to mitigate this risk that I am considering/have considered are:
store the text inside the project, as a global variable. Good because it's not exposed to the user, but unfortunately this means every time I need to make changes to the query, I have to transform the query into chunks, escape quotes, use line continuation, add line feeds and concatenate each chunk together. Yuk.
store the text in a module wrapped in directives not to compile it, then use VBE methods to retrieve and parse the text in from the module lines. Better than above but requires VBE to be enabled by end-users. That counts this option out.
keep the text in an external file, but obfuscate it (e.g. Base64 encode it). Adds some (acceptable) overhead for edits to the file, but requires a base64 decoding method in the project (does VBA have one?).
as above but use encryption of some kind - again, needs a decrypting method in the project.
store the text in a securable file-based format (eg .mdb or .accdb) and code credentials into the Visio project to retrieve the text.
Any recommendations or experiences? Have I missed some straightforward option that VBA offers?
Why not store the query string in the remote database and retrieve it when you need it? You can maintain the string in that database and use the database [read-only] protection to prevent ordinary users from altering it.
The table could look like TABLE QUERYSTRINGS (QueryName, QueryString).
The query could be "SELECT QueryString FROM QUERYSTRINGS WHERE QueryName='MyQuery';"
May I suggest another solution? Keep in the "very hidden" sheet.
Copy the SQL query to a sheet (one row, or many, up to you); then go to the VBA (macro editor, IDE, however you call it) and in the project menu select the sheet; finally in the properties window (press F4 if you cannot see it), select:
Visible = 2 (xlSheetVeryHidden)
That way a user will not see the sheet and the code, and as long as you protect the project with a password, the user will not be able to access it.
I have a do file from which I would like to select a few lines of code and then run them using the Execute (do) button. The problem is that there are a bunch of local macros defined in this do file. I can run them, but then in the Stata command prompt the local macros are not accessible. Thus, I think I should just be using global macros.
I have looked in several places and haven't been able to find out what scope macro variables actually have. I realize that local macros are only defined in the instance (for example, a do file) they are originally created in.
But for global macros, are they stored forever and every time I open up a new instance of Stata I will still have the global macros from previous sessions?
Or do they get deleted each time I exit out of Stata (or something else)?
Global means visible everywhere, but not for all time.
Global macros you create disappear at the end of a session.
When you start a session, or indeed at any time, macro list shows global and also local macros visible within your current locale. Here "locale" is not a word used in Stata documentation, but a nonce coinage to denote the current interactive session, the current program, the current contents of the do-file editor or a selection thereof, namely the code currently running. The difference is that local macros are only visible within the locale in which they are defined; global macros are visible in any locale.
Some global macros appear to be created on the fly; thus if I wish for a display of current date or time I can
di "$S_DATE"
di "$S_TIME"
and Stata will access the operating system for such details.
But the easiest way to answer your question is to experiment. Define some global such as
global whoami "bill999"
di "$whoami"
and then sign off and start a new session and see whether it is saved by Stata. Alternatively, save the current dataset and use the same dataset in a new session and see whether globals survive the journey.
See also help notes.