I want to format a drive from visual basic application. Can anybody help me with it ? I have tried shFormat(), but it is not completing my task. And If I Format my drive through CMD, it should be a background process for my application.
Asked
Active
Viewed 685 times
1 Answers
1
You could call a cmd from vba to execute the format command e.g.
Dim cmd_str As String
cmd_str = "cmd.exe /C format f:"
Call Shell(cmd_str, vbNormalFocus)
obviously the example above is for drive f:, change this as needed.

ChrisProsser
- 12,598
- 6
- 35
- 44
-
Can you please tell how can I make this process hidden i.e. the cmd should open as a background process. – PG1 Jan 25 '14 at 09:36
-
1Hi, try replacing the `vbNormalFocus` with `vbMinimizedNoFocus`, more info can be found here: http://office.microsoft.com/en-gb/access-help/shell-function-HA001228906.aspx – ChrisProsser Jan 25 '14 at 15:36
-
Yeah I tried this but to execute the commands the user have to press **ENTER** manually , is there I can give the **ENTER** command in my code so that we can hide **cmd** and the command executes successfully. – PG1 Jan 25 '14 at 16:55
-
1Hi, you can bypass the checks if you use the /y parameter, so the cmd string would become: `cmd_str = "cmd.exe /C format f: /y"`, if you want a quick format use `cmd_str = "cmd.exe /C format f: /q /y"` – ChrisProsser Jan 26 '14 at 16:10