I'm working on Excel 11 Mac OS and below is the code I'm using for creating a folder
Function MakeFolderIfNotExist(Folderstring As String)
Dim ScriptToMakeFolder As String
Dim str As String
If Val(Application.Version) < 15 Then
ScriptToMakeFolder = "tell application " & Chr(34) & _
"Finder" & Chr(34) & Chr(13)
ScriptToMakeFolder = ScriptToMakeFolder & _
"do shell script ""mkdir -p "" & quoted form of posix path of (" & _
Chr(34) & Folderstring & Chr(34) & ")" & Chr(13)
ScriptToMakeFolder = ScriptToMakeFolder & "end tell"
On Error Resume Next
MacScript (ScriptToMakeFolder)
On Error GoTo 0
Else
str = MacScript("return POSIX path of (" & _
Chr(34) & Folderstring & Chr(34) & ")")
MkDir str
End If
End Function
After I call the function using
MakeFolderIfNotExist("/Desktop/test/2017")
I'm getting the error saying path not found. I've been searching the internet for good 2 hours now with no luck. can somebody please help?
Related
The code works without error and opens the application 7zip with folder but does not extract the text file.
Sub B_UnZip_Zip_File_Fixed()
Dim PathZipProgram As String, NameUnZipFolder As String
Dim FileNameZip As Variant, ShellStr As String
PathZipProgram = "C:\Program Files (x86)\7-Zip"
If Right(PathZipProgram, 1) <> "\" Then
PathZipProgram = PathZipProgram & "\"
End If
If Dir(PathZipProgram & "7zFM.exe") = "" Then
MsgBox "Please find your copy of 7z.exe and try again"
Exit Sub
End If
NameUnZipFolder = "C:\vba\"
FileNameZip = "C:\vba\zout.Gz"
Shell (PathZipProgram & "7zFM.exe e -aoa" _
& " " & Chr(34) & FileNameZip & Chr(34) _
& " -o" & " " & Chr(34) & NameUnZipFolder & "*.txt*")
MsgBox "Look in " & NameUnZipFolder & " for extracted files"
End Sub
I used Shell Script, but it doesn't extract the file.
I have written some code that converts my Excel file into a XML data form, however I cannot figure out a way to save the new document to a specific location with a specific name.
So far I have tried to find some that will give me the option to save the filename, however everything I have found so far will only let me put in a path name when I attempt to save it. Like Document.Save "Path" will only allow me to save to the path location and will not keep the file name that I have stored in a variable.
xslDoc.LoadXML "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" _
& "<xsl:stylesheet version=" & Chr(34) & "1.0" & Chr(34) _
& " xmlns:xsl=" & Chr(34) & "http://www.w3.org/1999/XSL/Transform" & Chr(34) & ">" _
& "<xsl:strip-space elements=" & Chr(34) & "*" & Chr(34) & " />" _
& "<xsl:output method=" & Chr(34) & "xml" & Chr(34) & " indent=" & Chr(34) & "yes" & Chr(34) & "" _
& " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "/>" _
& " <xsl:template match=" & Chr(34) & "node() | #*" & Chr(34) & ">" _
& " <xsl:copy>" _
& " <xsl:apply-templates select=" & Chr(34) & "node() | #*" & Chr(34) & " />" _
& " </xsl:copy>" _
& " </xsl:template>" _
& "</xsl:stylesheet>"
xslDoc.async = False
doc.transformNodeToObject xslDoc, newDoc
Dim Docname As String
Docname = "VMM_" & SN.Text
fileSaveName = GetSaveAsFilename(InitialFileName:=sItem * Docname, filefilter:="XML Files (*.xml),*xml")
newDoc.SaveAs Filename:= fileSaveName, FileFormat:=xlTextPrinter, CreateBackup:False
I found code that helped me convert my code to XML which is the first part of it, however I cant find out how to use the SaveAs with the newDoc which is a MSXML2.DOMDocument60. I'm trying to save it with the filename Docname, in the location which is called sItem, any help would be greatly appreciated
I am on MAC so even if I know VBA i dont know how to translate it on MAC. I have this code but I have a problem about the path
I want a macro who join a specific document (already existing) in this path :
Path = "Z:\Reporting\" & ext3 & "\" & ext & " - " & ext2 & ".pdf"
(with ext1/2/3 are cells value)
and sending it by mail with Outlook MAC.
This is my code :
Sub SaveMailRangeAsPDFIn2016()
Dim FilePathName As String
Dim strbody As String
FilePathName = ?
'Create the body text in the strbody string
strbody = "<FONT size=""3"" face=""Calibri"">"
strbody = strbody & "Hi there" & "<br>" & "<br>" & _
"This is line 1" & "<br>" & _
"This is line 2" & "<br>" & _
"This is line 3" & "<br>" & _
"This is line 4"
strbody = strbody & "</FONT>"
MacExcel2016WithMacOutlookPDF _
subject:="test", _
mailbody:=strbody, _
toaddress:="xxxxx#xxxx.xx", _
ccaddress:="", _
bccaddress:="", _
displaymail:="yes", _
accounttype:="", _
accountname:="", _
attachment:=FilePathName
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
with the fonction :
Function MacExcel2016WithMacOutlookPDF(subject As String, mailbody As String, _
toaddress As String, ccaddress As String, _
bccaddress As String, displaymail As String, _
accounttype As String, accountname As String, _
attachment As String)
Dim ScriptStr As String, RunMyScript As String
ScriptStr = subject & ";" & mailbody & ";" & toaddress & ";" & ccaddress & ";" & _
bccaddress & ";" & displaymail & ";" & accounttype & ";" & _
accountname & ";" & attachment
'Call the RDBMacOutlook.scpt script file with the AppleScriptTask function
RunMyScript = AppleScriptTask("RDBMacOutlook.scpt", "CreateMailInOutlook", CStr(ScriptStr))
End Function
MacOS/OSX uses a different path separator than Windows "\".
So if you have your path hard coded in VBA like this
Path = "Z:\Reporting\" & ext3 & "\" & ext & " - " & ext2 & ".pdf"
you can check the operating system and use
If Application.OperatingSystem Like "*Mac*" Then
Path = "your mac path"
Else
Path = "Z:\Reporting\" & ext3 & "\" & ext & " - " & ext2 & ".pdf"
End If
Note that Application.PathSeparator returns the actual path separator used by the operating system.
I am trying to display the contents of a text file in notepad++ on the screen using line below the vba. Currently the rest of the vba runs and I can see the text file to be displayed in the directory var, which has the path to the directory, but only notepad++ opens and does not display the file. Is there a better way rather then Call Shell as I can not seem to fix this or what am I doing wrong? Thank you :).
vba
'UPDATE PERL VARIABLES USING SHELL '
Dim PerlCommand As String, PerlParameters As String, VarDirectory As String
Dim var As String, var1 As String, var2 As String, var3 As String
VarDirectory = "N:\path\to\data\" & "2571683" & MyBarCode & "_" & Format(CDate(MyScan), "m-d-yyyy")
var = VarDirectory
var1 = "sample_descriptor.txt"
var2 = "C:\cygwin\home\user\test_probes8.txt"
var3 = var & "\" & "output.txt"
var4 = var & "\" & "list_spikeins.txt" 'MATCH '
'CALL PERL '
PerlCommand = """C:\Users\user\Desktop\folder\file\perl.bat"""
PerlParameters = """" & var & """" & " " & _
"""" & var1 & """" & " " & _
"""" & var2 & """" & " " & _
"""" & var3 & """" & " " & _
"""" & var4 & """"
CreateObject("wscript.shell").Run PerlCommand & " " & PerlParameters, windowsStyle, waitOnReturn
MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss") 'SECONDS ELAPSED '
MsgBox "The ImaGene and the spike-in verification process completed in " & MinutesElapsed & " minutes" & " " & "these are the values:", vbInformation 'NOTIFY IN MINUTES '
Call Shell("C:\Program Files (x86)\Notepad++\Notepad++.exe " & "var" & "\" & "list_spikeins.txt", vbNormalFocus) ' DISPLAY IN NOTEPAD++ '
I am experiencing this runtime error - type mismatch on the following function call in VBA
Dim sTest As String
sTest = "=Search(" & Chr(34) & "MyString" & Chr(34) & Chr(44) & "A2" & ")>0"
''the above evaluates to =Search("MyString",A2)>0
Application.Evaluate(sTest)
So the evaluate function throws a runtime error-type mismatch
I tried
sTest = "=Search(" & Chr(34) & "MyString" & Chr(34) & Chr(44) & Chr(34) "Test MyString" & Chr(34) ")>0"
Still the same error
When I use the above string in the excel formula bar, it works!!
I tried
sTest = "=Search(""MyString"", ""Test MyString"")>0"
It Worked in VBA
To My Surprise
sTest = "=Search(" & Chr(34) & Chr(34) & "MyString" & Chr(34) & Chr(34) & Chr(44) & Chr(34) & Chr(34) & "Test MyString" & Chr(34) & Chr(34) & ")>0"
Din work
Could somebody help here why the first block of code does not work?
If you want to include a quote in a string all you need to do is double it up:
sTest = "=Search(""MyString"",A2)>0"
to me that's easier than using Chr(34)
Note that SEARCH() returns an error if the string was not found, not 0.