In my excel VBA code I'm automating the process of running a script ("PULLSCRIPT", which is also created in the code) that runs ftp, opens my FTP address, enters my user and password, pulls a file using mget, and lastly moves that file to another folder using Name. It works in Excel VBA (I click a macro and it does all these steps, no manual input required), but when I copy and paste it to PowerPoint VBA, the line
Shell ("ftp -s:" & sWorkingDirectory & FTP_BATCH_FILE_NAME)
doesn't run. It doesn't give me an error and, F8 stepping through it, it looks like the shell opens (just like when I step through it in Excel), but it never runs PULLSCRIPT (or if it does then it's not working). When I manually open cmd and run the PULLSCRIPT it works, but the point of automating it was so people wouldn't have to do that.
To debug the command execution, add cmd /k in front of it:
Shell ("cmd /k ftp -s:" & ...)
This way, the console window stays open and you can see, what went wrong.
Related
I am using Automation Anywhere for inserting values into an excel file. I used thie below code for opening the spreadsheet.But the spreadsheet is opening in excel app instead of Microsoft Excel in my computer. I don't have the license for Outlook Excel App.
Excel: Open Spreadsheet "C:\Users\my_user\Documents\xyz.xlsx".ActiveSheet:"Default".Contains Header,Session:Default
Can anyone help me on this issue?
I would recommend:
Open regedit -> navigate to
Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\(your version
here:probably 14.0)\options
From "File" create a new DWORD, call it
NoRereg, and set its value to 1
After that - you'll need to go to the
Programs and Features and repair Excel or the Office suite depending
on how its installed
Restart afterwards
If the above is not an option on your environment, you can always do:
Launch Excel from C:\Program Files (x86)\Microsoft Office\Office14\Excel.exe
Object Cloning-Set Text or keystrokes into Excel window to do CTRL+O
Type in path name of file and press enter
Try this:
Create File "C:\Users\cxcioba\Desktop\Test.xls"
Excel: Open Spreadsheet "C:\Users\cxcioba\Desktop\Test.xls".ActiveSheet: "Default". Session: test
From your code I'd change to *.xls
If you are trying to open in that way . go to c drive in your machine and look for the microsoft excel in the program files . you can use the same .exe in " Open program file " command
I want to see who locks a file, quickly.
So I created a CMD script that will run Handle, put its output in a file and then open that file in the default text editor.
prompt $
cls
handle > handle.txt
handle.txt
When I run the script a new console wnd is open, I see handle running in it, then it quickly closes. It generates a file called handle.txt, but it is empty.
I tried to run handle.exe as admin, but still doesn't work.
What I do wrong?
I have a small program that reads a CSV file and outputs it in a different format.
Sometimes I want a different output format so currently I just have another version of the program compiled with slightly different code (it has no GUI, you just click on the exe and it does its job).
Is there a way I can add an option to the context menu of this program to use the different output option, perhaps by running it with a command-line argument?
I mean when right-clicking on the exe file itself, so before it is actually running.
Anything I can find when searching for answers is about editing the shell, via the registry or some other way, however I only want the option to show for this program, not every file in Windows.
Code for the command line that I would be using:
If Environment.GetCommandLineArgs.Count <> 1 Then
If Environment.GetCommandLineArgs(1) = "/output2" Then
'do stuff
End If
End If
I used Shell command from Excel VBA to run a certain .bat file. The CMD appears but exits automatically after all lines were executed. I've added the PAUSE command a the end of the bat. file but it's not working. How to stop command prompt from getting automatically closed?
Try using the /K switch to prevent exiting after running the batch file like this:
cmd /K "path to batch file including file name and extension"
e.g.
cmd /K "C:\FOLDER\BATCH FILE.BAT"
or
cmd /K "C:\FOLDER\BATCH FILE.CMD"
Obviously that won't reveal any faults with your batch code, but it won't exit after running - much the same as running the batch file from the command line.
Definitely add some ECHO output lines to indicate progress as it runs and troubleshoot. Perhaps post the file here for more help.
Try opening the command prompt and running the batch file. It is possible that the the dos shell is encountering an error and closing. If the error comes before the execution reaches Pause command, it will not pause for you to read the error and it immediately closes off.
If that doesn't work out, check if you have any exit commands in any of the branches. Alternatively, place echo statements at different places and check if the execution control reaches these echos. This way you can find out if your script if ending at some other branch.
While perhaps not actually answering the posted question, I stumbled upon this question in a search to a very related-question. I was also trying to stop a command prompt from closing as it was erroring out and closing immediately. For me, it was sufficient for me to view the output as what I really wanted was to be able to see the error in order to debug it.
The solution I found was to pipe the output of the command prompt into a text file, like so:
MyScript.bat >> text.txt
This allowed me to see the error I was getting.
I have an Access database application and I would like to know the proper way of decompiling and recompiling it.
To Decompile an Access database you'll need to create a shortcut with the following elements:
Path to the MS Access Executable (MSACESS.exe)
Path to the database you would like to decompile
The /decompile flag
All together, then, the shortcut would look something like the following:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\users\tim\documents\Mydatabase.mdb" /decompile
Obviously, the paths will be different on your system.
I'd recommend making a backup of your database before running this command.
If you have any startup code in your database you should hold down the shift key to bypass the startup code execution.
Once the database opens, you can compact and repair the database to ensure optimal performance.
After the compact and repair, you can recompile the VBA code by opening any module and using the Debug Compile [DatabaseName] command.
If this is something you want to do frequently, you can create an "Access Decompile" shortcut in your SendTo Menu. Once you have this shortcut in the SendTo Menu you'll be able to right-click on any Access database and select "Send To --> Access Decompile", which is much easier than having to create a shortcut to the specific database.
Follow these steps to customize the Send To menu with an Access Decompile shortcut
Create a shortcut to the Access executable.
Append the /decompile flag in the Target for the shortcut. The shortcut will look like this:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile
Open Windows Explorer and paste the following into the address bar:
%APPDATA%\Microsoft\Windows\SendTo
Copy the shortcut you created into the SendTo Folder.
The Access Decompile Shortcut will now be available for use.
To invoke the Access Decompile shortcut, right click on an Access Database in Windows Explorer and select "Send To --> Access Decompile". Be sure to hold the shift key down to bypass any startup code in the database.
#Tim Lentine's practical instructions are good, but he leaves out the actual steps required for a decompile to be worth doing:
backup your database.
compact your database.
using the shortcut created with Tim's instructions, open your database.
close that instance of Access.
open a new instance of Access and open the database you just decompiled, but BE SURE YOU BYPASS ALL STARTUP CODE (i.e., hold down the shift key). If you don't do that, then you might as well go back to step 3 and try again, since if the startup code runs, your code will recompile before you are ready to do so.
compact the decompiled database (and be sure you hold down the shift key so that it bypasses the startup code; see #5).
open the VBE and on the Debug menu, choose COMPILE [name of project].
on the file menu, save the project.
compact again.
Why are all these steps necessary?
Because you want to not just decompile the VBA, you want to make sure that all the data pages where the compiled p-code was stored are completely discarded before you recompile.
I also recommend:
in VBE options, turn off COMPILE ON DEMAND
in the VBE, add the COMPILE button to your toolbar.
compile often with that button on the toolbar, after every two or three lines of code.
Decompile is not something you should use all the time, but during heavy-duty coding, I might do a decompile a couple of times a day. And I generally decompile/recompile as the last step before releasing an app into production use.
Last of all, read Michael Kaplan's article on the subject to understand it better.
The accepted answer is great, but it's a little impractical to create a shortcut for every database.
You can save this as a powershell module.
#for use with MSAccess 2010
Function Decompile-AccessDB{
param ([string]$dbFileName)
[string]$argument = '"' + $dbFileName + '"' + "/Decompile"
Start-Process -FilePath 'C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE' -ArgumentList $argument
}
Then call it like this:
Decompile-AccessDB -Path "C:\Path\to\some.accdb"
This allows you to quickly and easily decompile any db from the power shell command line.
Note that you still need to hold down the Shift key when you run this to bypass the application startup.
I wrote a VBS script to automate the process of decompiling. It's silly that Microsoft hasn't integrated this into Access, considering it is a necessity when developing VBA-heavy applications.
The script locates MSACCESS.exe and runs Access with the decompile flag on a database located in the parent directory of the script, whose name is given in the code.
Option Explicit
Dim MSAccPath
Dim RegKey
Dim WSHShell
Dim currentDirectory
' Get MSACCESS.exe directory
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
& "CurrentVersion\App Paths\MSACCESS.EXE\Path"
Set WSHShell = WScript.CreateObject("WScript.Shell")
' Get parent directory
MSAccPath = WSHShell.RegRead(RegKey)
currentDirectory = WSHShell.CurrentDirectory
' Decompile
WSHShell.Run Chr(34) & MSAccPath & "MSACCESS.EXE" & Chr(34) & " " & Chr(34) & currentDirectory & "\..\testdb.accdb" & Chr(34) & " /decompile"
' Clear shell var
Set WSHShell = Nothing
Simply paste this text into a document with a .vbs extension and double-click it to run. Access will launch, decompile the compiled P-code ("packed" code), and automatically recompile the VBA source back into P-code.
The other answers here all seem a little complex to my taste.
To decompile an Access database:
Open the Run dialog from the start menu, or hit Win + R
Type in: MSACCESS.EXE /decompile (a proper installation should open up the Access application, you could also provide the full path to MSACCESS.EXE), and press OK.
Access now opens. Open up your DB in the Access window that just opened. That will decompile it.
Or simply you can create a shortcut on your Desktop (with the /Decompile Flag) and drag drop your Access application holding SHIFT to bypass any code