Using the Shell macro

I’ve seen answers to this but I cant seem to make any of them work.
All I want to do is open a pdf I create in a macro
I’m trying the command

Shell(cmd.exe,1,“start pathtopdf”)
it doesn’t give me any errors but it also doesn’t work. if I type the command in cmd.exe
it works just fine whats going on?

macros are sometimes weird, we’d construct a macro to do something similar - and more, saving a timestamped copy - i think you can use some parts of it … specially from the end where the file is reopened,

sub schliessenoeffnen ' *******************************br 26.09.2019  

Dim oDoc, oForm, oblatt, oDatei as Object 
 
' remember file 
odoc = thiscomponent 
speicherOrt = ConvertFromUrl(odoc.getLocation) 

' strip if timestamped, apply new timestamp, save
extens = Right(speicherort,4)
dateilen = len(speicherort)-4
dateibase = left(speicherort, len(speicherort)-4)
tail = right(dateibase,17)
tlen = Len(Tail)
  pos1 = instr(tail,"_")
  pos2 = instr(tail,"-")
  if pos1 > 0 and pos2 > 0 then
    if pos1+ 5 <> pos2 then 
      notimestamp = true
    else
      if Mid(tail, pos1+ 11,  1) <> "_" or Mid(tail, pos1+ 8, 1) <> "-" or Mid(tail, pos1+ 14, 1) <> "-" then
        notimestamp = true
      else
        dateibase = left(dateibase,len(Dateibase)-tlen) 'strip old timestamp
      end if   
    end if  
      dateibase = dateibase & "_" & Format(Now(),"YYYY-MM-DD") & "_" & format(time(),"HH-MM" 'add new timestamp
  else
    dateibase = dateibase & "_" & Format(Now(),"YYYY-MM-DD") & "_" & format(time(),"HH-MM"
  end if
fname = dateibase & extens
surl = converttourl(fname)
dim dummy()
odoc.storeasurl(surl,dummy())

' Formular schliessen 
oDoc = thisComponent.currentController.frame
oDispatch = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatch.executeDispatch(oDoc, ".uno:CloseDoc", "", 0, Array())

' Formular öffnen 
DIM sDatei, sPfad as string
oDoc = ThisComponent
sDatei = fname

sUrl_1 = ConvertToURL(sDatei) 'Umwandeln URL
sPfad =  "scalc.exe" 'Pfad der zu verwendenden Applkation
Shell(sPfad + " " + sDatei,3) 'nun öffnen der Datei mit dem angegebenen Programm

end sub 'schliessenoeffnen ' *******************************br 26.09.2019

hope it helps, some comments are in german, sorry, deepl may help …

I tried to get it to work that way. I’m still not returning any errors, but the action isn’t happening. I have it printing the command before it runs it and I can copy and paste that into a cmd and it works fine. I don’t know what to do

Perhaps the cmd.exe does not understand what exactly needs to be done with the PDF file? Try to be more specific:

Shell(ConvertToURL("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"),_
   2,""""+pathtopdf+"""")

I was thinking that. so I tried to get it to PWD or anything else and it doesn’t do anything either. I tried assigning the output to something and printed that out and all it returns is 0.

I’d updoot ya but I can’t. I guess the Shell command isn’t running an actual CMD prompt? I think what I was missing was the convertToURL to point to the program. Everything I could find showed examples typing “CMD.exe”