TROUBLESHOOTING: Run-time error '13' - Type Mismatch

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by JimmyC »

I am trying to piece together code from the internet to make a VBA solution work. I am getting a "Run-time error '13' Type Mismatch with the following code highlighted in the debugger. I have researched this error on the internet but I can't discern what is incorrect with the code below to generate this error:

Code: Select all

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    FileName:=ActiveWorkbook.Path & "/" & mywsname & " - " & Range("A21").Value & ".pdf", _
    openafterpublish:=False

Any help, and assume I do not know what I doing, is appreciated.
JimC

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by HansV »

Assuming that you're on Windows, the path separator should be "\" instead of "/".
What is the value of cell A21?
Best wishes,
Hans

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Re: TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by JimmyC »

Hans,
As always THANK YOU. I missed the separator error as I am on Windows but when I went back to review the source and my notes, it appears the code was provided from a MAC version of excel. I do not know if this is what caused the erroneous separator. When I research cell A21, it was the incorrect reference and cell B22 should have been referenced. The code is not working. Again, thank you. Best wishes for an enjoyable weekend.
JimC

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by HansV »

"The code is not working" or "The code is now working"?
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by HansV »

You can avoid the Windows/Mac problem by using Application.PathSeparator instead of "/" or "\". That way, the code will work on both platforms.
Best wishes,
Hans

snb
4StarLounger
Posts: 587
Joined: 14 Nov 2012, 16:06

Re: TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by snb »

No need to specify defaults.
Avoid spaces in file/folder names.

Code: Select all

ActiveSheet.ExportAsFixedFormat 0, ActiveWorkbook.Path & "\" & mywsname & "_" & [A21]

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Re: TROUBLESHOOTING: Run-time error '13' - Type Mismatch

Post by JimmyC »

Hans, snb,
Thank you for the clarification and advice. I am learning VBA though at slow pace.
JimC