方法'保存为对象'_工作簿失败

时间:2015-10-06 13:20:31

标签: vba excel-vba excel

我无法将我的Excel PDF“保存为”我的工作表CSV以及将其保存为当前 ChDir "C:\Users\Owner\Google Drive\Lips\PDFs" <br> ActiveWorkbook.SaveAs Filename:=".pdf", FileFormat:= _ xlPDF 格式

这是我在调试器中给出问题的行

package com.example.vinita.pdfdictionary;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Environment;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;

public class Activity1 extends ListActivity {
    private File[] imagelist;
    String[] pdflist;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity1);
        File images = Environment.getExternalStorageDirectory();
        imagelist = images.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return ((name.endsWith(".pdf")));
            }
        });
        pdflist = new String[imagelist.length];
        for (int i = 0; i < imagelist.length; i++) {
            pdflist[i] = imagelist[i].getName();
        }
        Arrays.sort(imagelist);
        Arrays.sort(pdflist);
        this.setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,pdflist));
    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Intent intent=new Intent(this,Activity2.class);
        intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME,"mnt/sdcard/sample.pdf");
        startActivity(intent);

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_activity1, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

提前致谢!

2 个答案:

答案 0 :(得分:0)

您需要ExportAsFixedFormat方法:

Dim sPath as String, sFile as String
sPath = "C:\Users\Owner\Google Drive\Lips\PDFs\" 'this last backslash is necessary
sFile = Range("A1").Value & ".pdf"
sPath = sPath & sFile

'change other parameters as needed (can also use 'ActiveSheet` for just a given sheet
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= sPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= True

答案 1 :(得分:0)

您正在尝试将工作簿另存为PDF而不是工作表。要将当前工作表导出为PDF,您必须使用导出而不是保存命令:

ActiveSheet.ExportAsFixedFormat FileName:="MyFile.pdf" Type:=xlTypePDF

除此之外,问题可能是您直接保存到Google云端硬盘。虽然它具有Windows资源管理器集成,但您可能无法使用标准保存操作保存到它。

快速测试是尝试手动执行此操作。做文件&gt;另存为,看看是否可以浏览(通过文件夹浏览器)到此位置并成功保存。如果Google云端硬盘仅作为“广告位置”提供,则您可能无法通过宏直接保存到该广告。如果是这种情况,您可以尝试this script尝试启用该功能但我自己没有尝试过,并且不确定它是否能解决您的问题。