开发者

Writing to an external file using ACCESS 97

I'm using classic VBA and I'm having problems creating an external file. Bassically using a table I want to create a standard txt file. I already found a way to check if the file exists and kill it.

If Dir("%USERPROFILE%\Documents\iMacros\Macros\CriarGDC.iim") <> "" Then
    Kill "%USERPROFILE%\Documents\iMacros\Macros\CriarGDC.iim"
    Else
    End If

and also a way to write all the lines I need

Open "%USERPROFILE%\Documents\iMacros\Macros\CriarGDC.iim" F开发者_如何学Cor Append As #1
    Print #1, "1100258698,4"
Close #1

and also found a way to launch firefox with the imacros file

Problem IS:

I CANNOT CREATE the file. I tried using

Shell ("cmd.exe")
SendKeys ("dir /s/b %USERPROFILE%\Documents\iMacros\Macros\*.itwontfindanything > %USERPROFILE%\Documents\iMacros\Macros\CriarGDC.iim")

But I'm having some permissions problems - windows 7 won't allow me to do that. A lot of people told me that the command

Sub WriteFile(ByVal FileName As String, ByVal Contexto As String)
  Dim fnum%
  fnum = FreeFile()
  Open FileName For Output As fnum
  Print #fnum, Contexto
Close #fnum
End Sub

Should work, but it just doesn't! Erm... Help.


When giving your WriteFile procedure a FileName which includes an environment variable (such as "%USERPROFILE%\Documents\foo.txt"), VBA gives me error #76, 'Path not found".

Use the Environ() function to resolve your environment variable before you give it to WriteFile.

WriteFile Environ("USERPROFILE") & "\Documents\iMacros\Macros\CriarGDC.iim", "some text"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜